I put a ticket in for you in the datamapper lighthouse bug tracker. http://datamapper.lighthouseapp.com/projects/20609/tickets/915-chained-finders-being-isolated In the dm-core/next this works fine, you won't have to manually add the ( ) to our condition.
John On Jun 18, 3:10 am, Aleks C <[email protected]> wrote: > Using dm-core 0.9.11, finder chaining can be broken by the unwary: > > Zoo.all(:conditions => ["tigers is null or lions is null"]) > Above works fine > > Zoo.all(:open => true) > > this also works fine. > > Assume we define some scopes.... > > def self.cats_missing > all(:conditions => ["tigers is null or lions is null"]) > end > > def self.open > all(:open => true) > end > > Now let's say we try this: > > zoos_open_but_missing_cats = Zoo.open.cats_missing > > We'll get the expected results. However, try this: > > zoos_open_but_missing_cats = Zoo.cats_missing.open > > You'll get some unexpected results, because this query (approx) is > getting generated: > > SELECT * FROM `zoos` WHERE tigers is null or lions is null and `open` > = TRUE > > which gets parsed like this (maybe mysql specific, but this is an orm > after all): > > SELECT * FROM `zoos` WHERE (tigers is null) or ((lions is null) and > (`open` = TRUE)) > > I might be expressing this badly, but I think any call to all or first > should be encapsulated prior to chaining so that order doesn't matter. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
