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

[7.x] use getTouchedRelations when touching owners #34100

Merged
merged 1 commit into from
Sep 3, 2020
Merged

[7.x] use getTouchedRelations when touching owners #34100

merged 1 commit into from
Sep 3, 2020

Conversation

patrickomeara
Copy link
Contributor

This allows overriding getTouchedRelations()

I want to update certain polymorphic parents.

Using the example from the documentation: if a comment is updated it should update post, but never video

class Comment extends Model
{
    protected $touches = ['commentable'];
    /**
     * Get the owning commentable model.
     */
    public function commentable()
    {
        return $this->morphTo();
    }

    public function getTouchedRelations()
    {
        return $this->commentable_type === 'video' ? [] : $this->touches;
    }
}

getTouchedRelations() isn't currently used in the framework anywhere, overriding it has no affect, it's simply a getter.

The alternative solution to my problem is to use setTouchedRelations() when the model is booted. However, overriding most get*() methods in the framework actually have an affect, whereas this one doesn't.

This is backwards compatible as the base getTouchedRelations() on HasRelationships simply returns $this->touches.

This allows overriding getTouchedRelations
@driesvints driesvints changed the title use getTouchedRelations when touching owners [7.x] use getTouchedRelations when touching owners Sep 3, 2020
@taylorotwell taylorotwell merged commit 0933309 into laravel:7.x Sep 3, 2020
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.

2 participants