-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
The associate
function of morphTo relation get wrong owner key
#37054
Comments
Heya, thanks for reporting. I'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up. laravel new laravel-issue-37054 --github="--public" After you've posted the repository, I'll try to reproduce the issue. Thanks! |
Hey, this is the repository of the issue, please take a look: Thanks ! |
This seems like a legitimate bug to me. I'm not sure how to solve this one though. Adjusting the |
Duplicate of #36644 This occurs when using different primary key conventions for two models that share the same polymorphic child. Use the $myRequest->createdBy()->disassociate();
$myRequest->createdBy()->associate($foo); |
Description:
When using the
associate
function of morphTo relation, the ownerKey did not get the model key name passed to theassociate
function. Currently, it's got the previous ownerKey.Steps To Reproduce:
my_requests (table)
MyRequestModel
AdminModel
TenantModel
MyRequestController
When I'm dumping the $myRequest, the
created_by
attribute is null but thecreated_by_type
was changed, so i was checked theassociate
function onIlluminate\Database\Eloquent\Relations\MorphTo
At the line
$this->foreignKey, $model instanceof Model ? $model->{$this->ownerKey ?: $model->getKeyName()}
the property$this->ownerKey
currently return the previous ownerKey (admin_id
) not the model passed to the function (tenant_id
)The text was updated successfully, but these errors were encountered: