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

Conversation

Projects
None yet
2 participants
@segadora
Copy link
Contributor

commented Sep 21, 2017

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);
Allow associate on MorphTo to accept null value
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

This comment has been minimized.

Copy link
Member

commented Sep 21, 2017

Merged.

@segadora segadora deleted the segadora:feature/allow-null-value-in-morph-to-associate-5.5 branch Jan 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.