Skip to content

Nested relations #18

@mathieutu

Description

@mathieutu

Hi, thanks for this package. This is a simple but neat idea!

I've a problem with nested relations.

Example (pseudo code):

Parent::all()->each(function (Parent $parent) {
    $parent->children->each(function (Child $child) {
        $child->grandChildren;
    });
});

Saying that I have 2 parents, that have 3 children each, which have 4 grandChildren each, so a total of 2 * 3 * 4 objects.

With a proper eager loading (load('children.grandChildren'))I should have ~3 sql calls, one for each type.

Here we have one call for the parents (default one), one call for the children (auto eager loading), and 3 calls for the grandChildren (because one for each collection of children), so a total of 5 calls instead of 3. And it will be the same for each sub level.

I don't know if I made me properly understood, as I'm not a native speaker, but I think this is a real problem.

I have some clues about how to adress that, but I'm not sure about it.

As we store the parent collection, we can store the relations that were called, and so for each level, we can get the first collection, and call a loadMissing with the nested new relations on it (parents->loadMissing('children.grandChildren') in our case).

What's are your thoughts about it? Do you have any better idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions