ormnestedfuelphp

Soft delete nested children


I have a model called 'Model_Announcement' which extends Model_Soft and another model called 'Model_Announcement_Comment' which extends Model_Nestedset.

The relationship between them is: Model_Announcement:

protected static $_has_many = array(
  'comments' => array(
   'key_from' => 'id',
   'model_to' => 'Model_Announcement_Comment',
   'key_to' => 'announcement_id',
   'cascade_save' => true,
   'cascade_delete' => true,
  ),
);

Model_Announcement_Comment:

protected static $_belongs_to = array('user', 'announcement');

Creating a comment works fine but deleting an announcement throws 'Orm\RelationNotSoft' error because announcement comments are Nested model and not Soft.

Any ideas on how to make this work?

Thank you in advance


Solution

  • Model_Announcement_Comment also needs to extend Model_Soft (not Model_Nestedset) for this to work. This is stated within the docs.

    The delete function will soft delete related models providing that cascade_delete is true. If the related model is not soft delete as well then a RelationNotSoft exception is thrown.

    https://fuelphp.com/docs/packages/orm/model/soft.html#/relations