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.7] Fix nullable MorphTo touching #27031

Merged
merged 1 commit into from
Jan 2, 2019
Merged

[5.7] Fix nullable MorphTo touching #27031

merged 1 commit into from
Jan 2, 2019

Conversation

staudenmeir
Copy link
Contributor

MorphTo has its own touch() implementation to handle nullable related models:

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();

However, this doesn't cover relationships with a custom $ownerKey:

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

    public function commentable() {
        return $this->morphTo(null, null, null, 'id');
    }
}

We have to check the actual parent key instead of the $ownerKey.

@taylorotwell taylorotwell merged commit 15cce29 into laravel:5.7 Jan 2, 2019
@staudenmeir staudenmeir deleted the morph-to-touching branch January 2, 2019 14:44
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