Welcome Guest, Not a member yet? Register   Sign In
What is the most efficient way to load multiple has_many relationships in DataMapper ORM
#11

[eluser]darkylmnx[/eluser]
Quote:Something like this should work without problems, it always has:

Code:
// Create User
$u = new User();

// add the group id and name to all users returned
$u->include_related('group', array('id', 'name'), TRUE, TRUE)->get();

foreach($u as $user) {
    echo("{$user->group->name} ({$user->group->id})\n");
}

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) {
      // will repeat the user->id for N group found
      echo $user->id . ' ' . $user->group->id;
}

while my question was more like for something

Code:
foreach($u as $user) {
      // will repeat the user->id for N group found
      echo $user->id . ' ';

     foreach($user->group as $g) {
           echo $g->id . ', ';
     }

     echo "\n";
}


Quote:I am project lead for another framework.

Which includes an ORM. Which in the next version will no longer have framework dependencies, so it could be used with other frameworks as well.

So indirectly, yes. Wink

guess you're talking about FUEL PHP 2.0 ? waiting for it's standalone ORM with impatience ![/code][/quote]
#12

[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... Wink

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
#13

[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)
#14

[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.




Theme © iAndrew 2016 - Forum software by © MyBB