On Jul 13, 2011, at 7:12 PM, Keith Devens wrote: > To start, here's a summary of my data model:
Thanks for the detailed explanation of your setup, it really makes helping so much easier. > Things that don't work as expected: > > 1. When I have a list of Entrys and get "entry.comments", DM helpfully > fetches all the associated comments for me. Not so with Tags. So DM > can avoid the n+1 query problem with one-to-many but not many-to-many > relationships? I'm not familiar with this limitation, but it's entirely possible. The 'fetches all the associated comments' feature is called Strategic Eager Loading in the docs, and I don't know whether it is or is not supposed to work for many-to-many (m:m) relationships. > Am I querying or configuring wrong or does DataMapper not handle these > types of things? I would start by adding a :child_key to each of the `belongs_to` relationships defined on EntryTag. Also, naming a 1:m (`has n`, aka OneToMany) relationship with a singular name may be problematic (eg., `Entry.has n, :EntryTag`), try making that plural (`has n, :EntryTags`). If that doesn't help, I would then try to add the :inverse option to each of the relevant relationships on each of the three models (Entry, Tag, and EntryTag). The :inverse option takes a symbol arg which is the name of the relationship on the target model that 'points back' to the source model on which the relationship is being declared. So: class Entry ... has n, :EntryTags, "EntryTag", :inverse => :entry has n, :tags, "Tag", :inverse => :entry ... end Relationships in DataMapper are effectively symmetrical, and if a given relationship pair can't be successfully matched to each other by the inference algorithms, all manner of weird behavior can result. In my experience I have found that getting extremely explicit has allowed me to work around what are likely bugs that looked intractable at first glance. I'm sure there are opportunities to 1) produce reduced test cases (your email is actually quite reduced, and would probably be a perfect cut-and-paste into the dm-core issue tracker: https://github.com/datamapper/dm-core/issues), and 2) track down and fix some issues (perhaps long-standing ones) if you have the time and energy. I hope this helps, Emmanuel -- 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.
