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

Wrong Results When Including hasManyThrough Relation #121

Closed
MannikJ opened this issue Oct 23, 2018 · 1 comment
Closed

Wrong Results When Including hasManyThrough Relation #121

MannikJ opened this issue Oct 23, 2018 · 1 comment

Comments

@MannikJ
Copy link

MannikJ commented Oct 23, 2018

Assume you have three tables/models A, B and C.
On A you define a hasManyThrough relation like this:

public function cees()
{
    return $this->hasManyThrough(C::class, B::class);
}

When you now try to include the cees relation with this package's QueryBuilder, attributes that are present in B (intermediate) AND C (target) are overwritten by the attributes of the intermediate model B.
However, when I manually eager-load the relation by passing the relation name to the normal Builder's with() function, nothing is overwritten.
So far I did not have the time to dive deeper into the package, but I assume it internally builds a custom query to load the includes, which is not correct in the specific case of hasManyThrough relations.
I would appreciate to tell me if this issue can be reproduced.

Edit: I am now sure the problem lies in the select * statement that is appended via closure if no fields are explicitly specified in Spatie\QueryBuilder\addIncludesToQuery(). Probably prefixing it with the correct table name like table.* could do the trick.

I think #118 would fix this issue.

@AlexVanderbist
Copy link
Member

#118 has since been merged! Feel free to open a new issue referring to this one if the issue persists. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants