lundi 23 décembre 2019

Remove morph relationship of 2 models

I want to remove the relationship between two models in a one-to-one polymorphic relationship. In the example below, I want both comment and post to exist but just remove the relationship netween them. That is I want to set commentable_id and commentable_type to null.

posts
    id - integer
    title - string
    body - text

videos
    id - integer
    title - string
    url - string

comments
    id - integer
    body - text
    commentable_id - integer
    commentable_type - string

relationship:

class Comment extends Model
{
    public function commentable()
    {
        return $this->morphTo();
    }
}

class Post extends Model
{
    public function comments()
    {
        return $this->morphOne('App\Comment', 'commentable');
    }
}

class Video extends Model
{
    public function comments()
    {
        return $this->morphOne('App\Comment', 'commentable');
    }
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2EKGLp9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire