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

More than one chained withPivot returns NULL while acessing a column from pivot table #33

Closed
antonioribeiro opened this issue Jan 14, 2013 · 4 comments

Comments

@antonioribeiro
Copy link
Contributor

Not really important, but I'm not sure if it is supposed to work or not but this is not working:

$this->belongsToMany('Country')->withPivot('regional_name')->withPivot('enabled');

But this is working fine:

$this->belongsToMany('Country')->withPivot('regional_name', 'enabled');

When i do:

$model->pivot->regional_name;

@jasonlewis
Copy link
Contributor

Looking at the source it looks like the listed columns are overwritten with each call to withPivot. Can you provide a real world example of why you'd want to chain multiple calls to withPivot when you can easily just pass an array or comma separated list of columns.

@antonioribeiro
Copy link
Contributor Author

Actually I don't need it, I just converted my L3 query to L4 and they were chained in L3, wich made me suppose that it should work chained in L4 too, but I don't really see a case when I would need it to be chained. :)

@jasonlewis
Copy link
Contributor

We'll see what @taylorotwell thinks about it. It's quite an easy thing to patch though. But yeah, generally you'd only have one call to it.

@taylorotwell
Copy link
Member

Yeah, just stick with one call.

gonzalom pushed a commit to Hydrane/tmp-laravel-framework that referenced this issue Oct 12, 2023
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