Reputation: 1014
I have two table:
menu: id, name
category: id,name, menu_id
here, category table have menu_id foreign key.
relation of menu models
'mnuCategories' => array(self::HAS_MANY, 'MnuCategories', 'menu_id'),
customizing delete button of CGridView
array(
'class'=>'CButtonColumn',
'template'=>'{update}{delete}
'buttons'=>array
(
'delete'=> array(
'click'=>'js:function()',
)
),
),
here I want to customize delete operation by checking if child record exist or count child record. If count is greater than one then alert user 'cannot delete! child record exist'. if count is zero then allow user to delete with confirmation message.
Upvotes: 0
Views: 1455
Reputation: 367
In your model add beforeDelete() function
protected function beforeDelete() {
parent::beforeDelete();
/*
* Check children
* 1. if (0 > $count > 2) return FALSE;
* 2. if ($count == 1) return TRUE;
*/
}
Upvotes: 1
Reputation: 7265
Or you can put a beforeDelete() function in your model and check your logic there and return FALSE if you want to prevent deletion.
Upvotes: 0