What would be the best way to define that related models should be cascaded or skipped when a parent is removed?

  • User
  • Blog Entry
    • BlogComment
  • BlogComment


A BlogComment would not be deleted when a User is deleted. However, it would be removed when a BlogEntry is removed.

So what would be the best way to define this inside the model classes?

PHP Code:
class BlogComment extends ActiveRecord {

      public static 
$cascadeDelete = array(
             
'User'=>array(false,false// skip, don't cascade when parent is User
            
,'BlogEntry'=>array(true,true// delete when parent is removed and cascade
      
)


That is what I'm currently thinking but I'm looking for possible alternatives.

The other thing I would like to implement is a way to define at run time the cascade.

PHP Code:
$user = new User(12);
$user->delete(array('BlogComment'=>array('User'=>array('false','false')))); 
That seems like a decent approach. In that a BlogComment with a direct parent of User would not be cascaded or deleted.

Based on the parent any related models can be excluded from being deleted or cascaded. However, I'm not sure on the best interface which to make this possible from the developers perspective.