Closed ChristopheB closed 4 years ago
@ChristopheB Thanks for the report. You can make a PR. I think this will introduce some breaking behaviours in some integrations. I will bump the version to 2.0
Just a side note on the presence of $this->query->whereNotNull($fullKey);
, as I struggled around it a bit: it is needed only when a local auto incremented primary key is used in the relationship.
In other words, it ensures the collection on a new instance without an id set is the same as the collection on the saved object with its definitive id.
I stumbled upon some unexpected results while working on a table where a column is nullable. If I were to use the example in the tests folder, pretending vehicle_id could be null, we would have:
And the result is fairly unexpected:
After some investigations, it turns out that this line is causing this issue.
The reason of the presence of this line in the Laravel repository is detailed here (PR here, and an interesting note here).
I think it could be possible to drop this whereNotNull condition when not all of the values are null, something like this:
I could make a PR for this if that new behaviour sounds good to you.
Thanks for your time, and thanks for Compoships.