I can’t get my AR model validated right. Or maybe this Exception is right and i assume wrong.
I always get Exception: "No columns are being updated for table xy".
but i’m don’t update just validate
// working with activeRecords
$model = new Xy();
$model->attributes = $_POST['Form'];
// all attributes are set correct
// a table row already exists with same Pk set
// I even do
$model->setIsNewRecord(false);
$model->setScenario('update');
$model->validate();
// Throws Exception: updateCDbException ... No columns are being updated for table model
// I expect it to validate cos all attributes are ok
Well, thanks for that. I always wondered why all data in actionUpdate is loaded first…
But now that this is in the right place I don’t really understand how to set new data do the related model.
i$_POST Data comes as an array for related models.
so how can i tell which related model[] to assign which _POST[][]
Yes, I read the Yii Guide but somehow i can’t get it.
Scenario
In actionUpdate I (now) load my model data with related models and want to assign my form data to the related models.
Related model comes as an array in POST[‘Offercontents’][] cos it’s a repeating form field.
public function actionUpdate(){
// load model and data from db
// related models are defined well in relations and stuffed with data
$model = Offer::model()->with('offercategories', 'offercontents', 'offerimages', 'offerlocations')->findByPk($id);
// its clear to manipulate $model itself
$model->attributes = $_POST['Offer'];
// but what about eg. offercontents? which is an array
// how to find the the right $model->offercontents[] to manipulate?
$model->offercontents[?]->attributes = $_POST['Offercontents'][?];
// i really can't see that $_POST['Offercontents'][?]
}
Sorry for being so complicated. but i can’t even express well what the problem is. But you get it.