-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix related records auto-save with belongsTo() relation #15203
Conversation
Note that this fix may not be perfect because when you access a linked record it seems to be saved anyway. According to my tests: $invoice = Invoices::findFirst();
$invoice->customer->name = "name";
$invoice->save(); // customer is saved 👍
$invoice = Invoices::findFirst();
$invoice->save(); // customer is not saved 👍
$invoice = Invoices::findFirst();
echo $invoice->customer->name;
$invoice->save(); // customer is saved 👎 Maybe there is something to do in |
We don't have knowledge about the state of the properties in (related) models.
|
|
Thank you for this clarification. Indeed, I did not know how to deal with |
@gponcon Thank you so much for the bug fix. Could you please change your target branch to be It is looking good |
f343dd9
to
1f6af91
Compare
@niden I modified the target branch as requested. Let me know if it is correct, I am at your disposal. |
1f6af91
to
dad4fbc
Compare
@gponcon Can you please rebase to the latest 5.0.x branch and add an entry to the changelog? Then we can merge this |
Closing in favor of #15838. Original work preserved |
Hello!
In raising this pull request, I confirm the following:
Small description of change:
Models: with a relation
belongsTo()
-hasMany()
, the related records need to be saved inpreSaveRelatedRecords()
. This fix update the dirtyState of related records to trigger related records save.