Skip to content

Add "Set null" behavior #130

@rikipm

Description

@rikipm

Add behavior similar to SET NULL action. It will set relation column to NULL when referenced model is deleted.

For example

Class User extends Model {
  use SoftDeletes, SoftCascadeTrait;
  
  protected $softCascade = ['phone@setNull'];
  
  public function phone()
  {
    return $this->hasOne(Phone::class);
  }
}

Class Phone extends Model {
   use SoftDeletes;
  
  public function user()
  {
    return $this->belongsTo(User::class);
  }
}

Will set NULL in phones.user_id if user was soft deleted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions