This overrides has() method to provide somewhat more efficient  
implementation of through-association.

http://pastie.org/309510

Default implementation constructs INNER JOIN query. My solution relies  
on Strategic Eager Loading in DataMapper:

Person#projects:
   memberships.map do |entity|
     entity.project
   end

This results in 2 SQL queries:
   SELECT * FROM project_memberships WHERE person_id = <self.id>
   SELECT * FROM projects            WHERE project_id IN  
(<self.memberships.map{|m| m.project_id}>)

The code can be extended in many ways (e.g. to support sharding  
scheme). At this point it fully supports setup where different tables  
are located on different nodes. INNER JOIN wouldn't work in such case  
(except Oracle, maybe).



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