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

Conversation

Projects
None yet
2 participants
@staudenmeir
Copy link
Contributor

staudenmeir commented Jan 2, 2019

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@staudenmeir staudenmeir deleted the staudenmeir:morph-to-touching branch Jan 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment