When I delete a ‘type’ i set isActive = 0;
Every ‘type’ ‘has many’ ‘causal’
So when disabling a type i want disable every causal
in type controller i’m trying this
$model = $this->loadModel($id);
$model->isActive = 0;
foreach ($model->causalsObj as $key => $causal ) {
$causal = CausalController::delete($causal->id);
}
$model->save();
This doesn’t work (PHP error during ajax call)
That should go into the model, not the controller, I’d use afterSave. so in the CasualType:
If you don’t actually mean ‘delete’ but deactivate you can still do this in one single query using CActiveRecord::updateAll:
Instantiating a controller in another controller does not make sense, controllers are there to handle user requests, not to hold your business logic