Here's the regression test for the awful bug:
http://github.com/oleganza/dm-core/commit/5aad41418a6529a126c823f8c84359583a50cdac

Line ~92 in relationship.rb contains something very nasty:

  return collection unless collection.kind_of?(Collection) &&  
collection.any?

This returns an object when #first was used and returned a single  
object. In the other case, it groups eager loaded results and returns  
an appropriate subset.

In my not so humble opinion, datamapper should not treat :first finder  
as alternative for :all throughout the code. It should just add :limit  
at the topmost #first method and retrieve first element of the  
resulting array/collection in the very same topmost #first method.  
Other low-level code should operate Collections only.
Currently, first element retrieval ("stripping array off") is done in  
the *Adapter#read_one method, all of them differ from the  
*Adapter#read_many in few bytes. I think, this is very wrong.

I suggest refactor the code so that :first finder is not fucking  
around the codebase along with obscure if-else branches to check  
results against something like kind_of?(Collection). It should not  
only fix the bug, but also look much clean and simpler.



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to