hi there
i’m really confused and frustrated saving a relational record. been bashing my head against this for days.
i have a model $artist and a model $aliases.
so in artists:
public function relations()
{
return array(
‘aliases’ => array(self::HAS_MANY, ‘Aliases’, ‘artist_id’)
}
so the relations are working fine.
i then load the $artists model and go and fetch data to update it. all elements of aliases are "safe":
public function rules()
{
array('id, artist_id, name, rank', 'safe', 'on'=>'search')
}
the fetch gets the data from an api and not from a form - most of what’s in the forum relates to forms.
if i do a print_r of the $artist->aliases after i load the model, i get a huge amount of other information, which i assume by looking at it, it’s the AR data. (i assume this is normal in Yii???)
so far so good.
once i fetch my new data, i want to update the $aliases table.
here i have tried two methods:
-
just returning the new values for aliases. which is $aliases[‘name’] and $aliases[‘rank’]. i have also manually inserted $aliases[‘artist_id’], because not sure Yii does this automatically.
-
passing the whole $artist model into my alises class and then returning the whole model (with all those extra arrays) with the new values set and then tried to save it.
i then try to save the model.
tried various things, nothing works.
the curious thing is, it still fires the view:
with if($model->save()) or if($model->save(false)) // to see if it’s a validation error
i’ve also tested to see if it’s a validation error but get no error.
if i do a trace in the view. the new values have been passed to the model. they are just not being saved??!!!
i’ve tried:
$model->save();
$model->save(false);
$model->save('aliases);
$model->update();
$model->update(false);
$model->update('aliases);
$model->setAttributes(‘aliases’, $aliases);
$model->attributes = $aliases;
any help would be appreciated.
thanks