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

BelongsToMany and paginateFilter() destroys pivot #43

Closed
Cannonb4ll opened this issue Nov 24, 2017 · 7 comments
Closed

BelongsToMany and paginateFilter() destroys pivot #43

Cannonb4ll opened this issue Nov 24, 2017 · 7 comments

Comments

@Cannonb4ll
Copy link

When using the method paginateFilter() on a model with pivot table, this pivot table is not present inside the model. When changing back to paginate() the pivot model is back.

companies - company_user - users

In this case, if I would get all the users inside a company, and there would be any additional data inside the pivot table, it would be added inside the 'relations' object inside the model, but this is not present.

@Tucker-Eric
Copy link
Owner

Can you provide a code example?

@Tucker-Eric
Copy link
Owner

Closing due to paginateFilter() calls the builder's paginate() method and this sounds like an issue with the query itself and not the paginateFilter() method.

We can reopen if there is an example that will replicate this behavior.

@rayronvictor
Copy link

@Cannonb4ll you can use the second parameter to specify what you want:
paginateFilter(perPage, ['*']) or
paginateFilter(perPage, ['companies.*']) or
paginateFilter(perPage, ['companies.*', 'company_user.*']) or
paginateFilter(perPage, ['companies.*', 'company_user.*', 'user.*'])

@Cannonb4ll
Copy link
Author

Cannonb4ll commented Jun 25, 2018

@Tucker-Eric Create the following relation:

user -> company_user <- companies

The table company_user is a pivot table, if I do the following methods, see the difference:

paginate <- Laravel's original method:

$companies = auth()->user()->companies()
    ->latest()
    ->filter(request()->all())
    ->paginate();

dd($companies->first());

img


paginateFilter <- This package's method:

$companies = auth()->user()->companies()
    ->latest()
    ->filter(request()->all())
    ->paginateFilter();

dd($companies->first());

img

You can see, the relations are now empty when using paginateFilter()

@Tucker-Eric
Copy link
Owner

@Cannonb4ll I was able to reproduce this and it should be fixed in 5583402

Are you able to pull the latest (dev-master) and confirm this is resolved?

@Tucker-Eric Tucker-Eric reopened this Jul 4, 2018
@Cannonb4ll
Copy link
Author

@Tucker-Eric Confirmed and is resolved with dev-master!

@Tucker-Eric
Copy link
Owner

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

3 participants