Ownership of what? There is CActiveRecord::beforeDelete(). Just overwrite it in your model and this is runned before your deletion process. If it is not the owner, return false and delete is not performed.
i mean multiple owners are there for data. when i use the simple deletebyAttribute ,the others with the same condition satisfies will be removed . so i want to avoid the deletion of the datas of other owners .
there is a field in every table named "tenant"
so as you said
protected function beforeDelete()
{
if ($this->tenant == "Myownerid")
{
return true;
}
else
{
return false; // prevent actual DELETE query from being run
}
}
public function deleteAllByAttributes($attributes, $condition = '', $params = array())
{
if ($this->beforeDelete()) {
return parent::deleteAllByAttributes($attributes, $condition, $params);
}
return false;
}
this will not work . it only check only once . if first attribute is getting true result it deletes all because , deleteAllByAttributes deleting in a single step .
i have only one option to use it everywhere is change the CActiveRecord , or add condition in the deleteAllByAttributes();
Ah right. But you do not have to change cactiverecord at all. Because there is nothing to change. If you have to check every record then iterate over objects and call delete everytime.
...
$models = Model::model()->findAll();
foreach ($models as $model) {
//calls before delete
$model->delete();
}
...
Or yeah, write condition to delete is the easiest way.