Hi Everyone, I just wanted to give everyone a follow-up on the new query improvements I hinted at last week. For those of you who missed it, here was the original post:
http://bit.ly/10gIJb As of a few minutes ago, I just committed changes that would permit Set operations to be performed on a Collection, eg: Union -------- Person.all(:name => 'Dan Kubb') | Person.all(:name => 'Alex Kubb') Person.all(:name => 'Dan Kubb') + Person.all(:name => 'Alex Kubb') # => SELECT "id", "name" FROM "people" WHERE ("name" = 'Dan Kubb' OR "name" = 'Alex Kubb') ORDER BY "id" Intersection ---------------- Person.all(:name => 'Dan Kubb') & Person.all(:name => 'Alex Kubb') # => SELECT "id", "name" FROM "people" WHERE ("name" = 'Dan Kubb' AND "name" = 'Alex Kubb') ORDER BY "id" Difference -------------- Person.all(:name => 'Dan Kubb') - Person.all(:name => 'Alex Kubb') # => SELECT "id", "name" FROM "people" WHERE ("name" <> 'Alex Kubb' AND "name" = 'Dan Kubb') ORDER BY "id" This should work fine with any kind of Collection that you return from "all", including 1:m and m:m associations. There's nothing special about these Collections, so you can still chain them, lazy load and do all the other things you've come to expect from DataMapper. I have not yet updated "all" chaining to use intersection, as I hinted in the original email. I wanted to get this out and tested before swapping DM's collection chaining algo with Collection#intersection. That probably won't happen until after the gem release this week. In case you're curious to see how this was implemented, check out these commits: Operation: http://bit.ly/2jTYs Query: http://bit.ly/IjyIR Collection: http://bit.ly/2AJ7Jy As you can see the implementation is fairly clean and simple. I'm guessing it took about 40-50 lines of actual code, although once I refactor collection chaining to use intersection there will probably be a reduction of about 200-300 loc overall. Actually there's more docs than code, and 5-10x more specs than that even! The new code is fully covered by the specs with rcov, and pass with heckle. If you haven't already done so, please checkout edge dm-core and play around with this to construct queries. Let me know of any issues you run into either on the mailing list, on IRC in #datamapper @ freenode.net, or in the ticket tracker: http://bit.ly/x8ZLU -- Dan (dkubb) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to datamapper@googlegroups.com To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---