Skip to content

Conversation

iamgergo
Copy link
Contributor

This is a retry of #46522, however I try to be more clear about the issue here, also added tests with another approach.


Due to Taylor's comment, my previous PR was closed, because the withPivotValue was mixed up with the withPivot method, however they are two diffent methods. (Also, as I see, the withPivotValue is not even documented, so if you wish, I gladly open a PR to document it, because I find it super handy.)

The withPivotValue defines a wherePivot statement and sets a pivot value when saving the relation. So it is used when saving AND retreiving relations.

The withPivot method just retrieves a pivot column, it does not even define a where statement.

When using the withPivotValue, that value is not being set when making a new pivot model using the relationship itself ($model->relation()->newPivot()).

It means, if a developer is using a custom pivot model, and that model has default attribute values using the $attributes array, when saving the relationship, the withPivotValue won't work, however it should override the proper attribute in the $attributes array.

@taylorotwell taylorotwell merged commit e1e796b into laravel:10.x Mar 28, 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

Successfully merging this pull request may close these issues.

2 participants