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.5] Allow associate on MorphTo to accept null value #21318

Closed
wants to merge 1 commit into from
Closed

[5.5] Allow associate on MorphTo to accept null value #21318

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

I would prefer if this also could be added to 5.4.

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
@taylorotwell
Copy link
Member

Merged.

@segadora segadora deleted the feature/allow-null-value-in-morph-to-associate-5.5 branch January 2, 2018 12:15
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.

None yet

2 participants