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.6] Fix nullable MorphTo and $touches #25438

Merged
merged 1 commit into from
Sep 4, 2018
Merged

[5.6] Fix nullable MorphTo and $touches #25438

merged 1 commit into from
Sep 4, 2018

Conversation

staudenmeir
Copy link
Contributor

Using $touches with a MorphTo relationships breaks without a related model:

Schema::create('comments', function ($table) {
    $table->increments('id');
    $table->nullableMorphs('commentable');
});

class Comment extends Model
{
    protected $touches = ['commentable'];

    public function commentable()
    {
        return $this->morphTo();
    }
}

Comment::create();

This throws an exception:

Unknown column 'comments.' in 'where clause'
(SQL: update comments set updated_at = 2018-09-04 02:24:54 where comments.`` is null)

We can detect this case by checking the $ownerKey and so prevent the invalid query.

Fixes #25434.

@jerguslejko
Copy link
Contributor

I can confirm that this fixes #25434 👍

@taylorotwell taylorotwell merged commit a8c5056 into laravel:5.6 Sep 4, 2018
@staudenmeir staudenmeir deleted the morph-to-touches branch September 4, 2018 13:04
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.

3 participants