Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge of nested relationships & includes on JsonApiCollection #11

Open
d8vjork opened this issue Dec 14, 2022 · 1 comment
Open

Merge of nested relationships & includes on JsonApiCollection #11

d8vjork opened this issue Dec 14, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@d8vjork
Copy link
Member

d8vjork commented Dec 14, 2022

Replication example

Loading something twice as on a polymorphic relationship and somewhere else (included as of a nested relationship), imagine something like:

// PostController.php

public function index(JsonApiResponse $response)
{
    return $response->using(Post::with([
        'parent' => fn (MorphTo $morphTo) => $morphTo->morphWith([
            Group::class => [
                'createdBy', // this being user ID = 2
            ],
        ]),
        'author', // this being user ID = 2
        'author.avatars', // load avatars from post.author relationship thought groups will not have access to this!
    ]));
}

This will get into a race condition where author relationship (in this case could be of type user) will be different sometimes at the included data array because the user is actually the same in both relationships...

@d8vjork d8vjork added the bug Something isn't working label Dec 14, 2022
@d8vjork d8vjork self-assigned this Dec 14, 2022
@d8vjork
Copy link
Member Author

d8vjork commented Jan 25, 2023

Similar issue happening but with a race-condition on the merge:

public function index(JsonApiResponse $response)
{
    return $response->using(Post::with([
        'updatedBy', // this being user ID = 2
        'author', // this being user ID = 2
        'author.avatars', // load avatars from post.author relationship thought race-condition will exclude this in favor of the first found in the array
    ]));
}

Reported by @danielperez9430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

1 participant