Modifying the standard AR delete behaviour

Hi,

I am building a site where the data involved needs to be kept continuously and never deleted.

In the past before using Yii i have included in each table a ‘state’ column - 1:online, 2:deleted so when a user ‘deletes’ something all they are actually doing is changing the state to 2.

So if the database has this state column what do you think the best method of achieving this would be:

[indent][list=1]

[*]Redefine the delete method in a bespoke AR

[*]Add a new method changeState() to each controller

[*]…or other?

[/list][/indent]

Thanks,

Julian

I use that in some models not all… so in those models I create the method changeStatus()… and from the controller delete action call it…

If it’s needed for all models than would be better to not duplicate the code…

hi mdomba,

so to clarify:

If its needed in all cases it would be better to override the standard AR behaviour

If its only necessary in some then write a bespoke changeStatus() method

?

In the end it’s all up to you as the coder…

If it’s needed in all models and if you have many of them… I don’t see the point of making duplicate methods in every class… right?

yep agree