Relations : Cascade Delete

Hi all,

Sorry if this is obvious …

I have 2 tables (2 Models) Post and Comment

but how would I go about deciding whether deleting a Post will delete all comments automatically ?

I know you can have the db to do it but is there another way ? (other than writing the code to do it :)

Is it supported ?

thanks a lot

thomas

Automatic deletion (or addition) of related objects is not supported. You will need to override afterDelete() to do this. The best way is to let DB do this.

thank you for the reply

is there any reason why this won't be implemented ?

As I see it right now I would have to issue an alter table statement each time I'd like to modify the behaviour I have setup when creating my app.

am I right ?

thanks if there is time to answer this

The reason we don't implement these automagic features is mainly because of potential usage complications. There's no problem technically. We may add support these in future, if there are many requests for them. Personally, I think having DB to maintain these deletion/updating is better than doing that in PHP.

Maybe this functionality could be implanted into a core behavior?  So if you wanted cascade delete, you could do this:

<?php


//User model


public function behaviors(){


	return array(


		'cascadeDelete' => array(


			'models' => 'Post',


		)


	);


}


Yes, that's a potential solution.

I understand

if ever I really need this feature to be attached/detached to/from a model I'll implement it as a behaviour and share.

Thanks for the replies