What is the most efficient way to load multiple has_many relationships in DataMapper ORM |
[eluser]darkylmnx[/eluser]
Quote:Something like this should work without problems, it always has: actually, yes this works, but does not return each model with it's relation in one array, it repeats a model N times the number of entry found for it's relation, which means we need to filter it after the query. EX: Code: foreach($u as $user) { while my question was more like for something Code: foreach($u as $user) { Quote:I am project lead for another framework. guess you're talking about FUEL PHP 2.0 ? waiting for it's standalone ORM with impatience ![/code][/quote]
[eluser]WanWizard[/eluser]
What happens when you run the code in the second example? You only get the first group? And I guess you're right... It solves a lot of issues that have been on the request list for DM for a long time: - proper object hydration - better relationships - no hardcoded "_id" suffix for FK's - no hardcoded requirements full-stop - compound PK support - built-in soft-delete functionality - built-in temporal functionality (versioning) - built-in EAV container support - full support for eager and lazy loading - cascading saves and deletes - observers for pre/post operations
[eluser]darkylmnx[/eluser]
[quote author="WanWizard" date="1363257123"]What happens when you run the code in the second example? You only get the first group?[/quote] lets say we have the 2 tables below user, group http://pastie.org/6491337 (to avoid long code in the post) so if you chekc out this link you see what dmz brings out with the include_related, and the question was can we make this more look like when you do a lazy load. (check out in the link too)
[eluser]WanWizard[/eluser]
Hmmm.... If you want lazy load, enable "auto population" on the relation, and access the property. That works now, and doesn't require include_related. The issue is with eager load, when you want to fetch the relations using a single join query, and you want to hydrate the resultset into the related objects. Problem there is that it is possible to add that (I've got it working here), but that would break all existing code that uses the current behaviour. i.e. your second example works, but now the first one is broken. So this functionality can not be added unless something can be found that doesn't break the current behaviour. |
Welcome Guest, Not a member yet? Register Sign In |