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

[5.4] Allow associate on MorphTo to accept null value #21319

Closed
wants to merge 1 commit into from
Closed

[5.4] Allow associate on MorphTo to accept null value #21319

wants to merge 1 commit into from

Conversation

segadora
Copy link
Contributor

This will make the MorphTo match the signature of BelongsTo.
BelongsTo can accept a null value on associate.
MorphTo would fail due that getKey() would not exists on null.
This should be possible also due to that is it possible to generate migrations with nullable polymorphic relations

Part of #21318

Example:

$model->user()->associate($user);
$model->customer()->associate($customer);
if ($morph_relation) {
    $model->morphRelation()->associate($morph_relation);
}

Can be turned into

$model->user()->associate($user);
$model->customer()->associate($customer);
$model->morphRelation()->associate($morph_relation);

This will make the MorphTo match the signature of BelongsTo.
BelongsTo can accept a null value on associate.
MorphTo would fail due that getKey() would not exists on null.
This should be possible also due to that is it possible to generate migrations with nullable polymorphic relations
@segadora
Copy link
Contributor Author

Would you allow this to be merged into 5.4 ? @taylorotwell

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