Bug or feature in count:where: ?

3 views
Skip to first unread message

Joachim Tuchel

unread,
May 2, 2024, 12:43:15 PMMay 2
to glorp...@googlegroups.com

Hi there, 


I just stumbled across an dnu error because of an unexpected result of a count:where: query in Glorp.

The problem is that an expression like


myDBSession count: MyClass where: [:obj| obj id = nil]


returns nil instead of zero. So when I ask the result of this query if it is greater than zero, I get "UndefinedObject does not unterstand >" .

The funny thing is that this also returns nil if you have something like


myDBSession count: MyClass where: [:obj| obj customer = self]


when self is a newly created, not yet saved object and therefor doesn't have an id (or better: an id of nil).  So there is not point in replacing the = test with == (which works for nil), because the actual situattion doesn't involve nil or some object, but instead objects whose ID might (still) be nil.

Is this expected behavior? Does Glorp behave the same on Pharo and VW (I am non VAST)?


My current workaround is this:

---

Customer>>#hasInvoices

    ^(myDBSession count: Invoice where: [:inv| inv customer = self]) 
		ifNil: [^false] 
    		ifNotNil: [:count| count > 0]


--- 

but honestly, I think this smells like a bug to me.


Joachim




Alan Knight

unread,
May 2, 2024, 1:48:13 PMMay 2
to glorp...@googlegroups.com
I'd be suspicious that this is related to the difference in database treatment of nil vs. Smalltalk. In particular, in the DB `== NULL` is always false. Null is not equal to itself, it needs to be an `is NULL` check.
It's possible Glorp is already compensating for this, but there might be a problem with it. It certainly seems like an undesirable behavior. I'd expect there ought to be a test case for that sort of comparison. Particularly the second case seems like it would be pretty common.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glorp-group...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/1dc89285-d55b-4e40-b6bb-05ae7fe17268%40objektfabrik.de.
Reply all
Reply to author
Forward
0 new messages