About Relations in Yii

Hi everyone i’m a newbie in yii and this is my very first post on this forum.

for example if i have a model for Reader and a model for InterestedTopics and a pivot table like (reader_id, topic_id) and the two models are in a MANY_MANY relationship, ie, a reader can have more than one interested topics and a topic can be followed by more than one readers.

now supposed I want to change one of the InterestedTopics for a particular Reader. It is assumed that the Reader can have several InterestedTopics and i only want to change one of them. I tried update() but this seems to replace all the current records with only the new one. I also thought about delete() and insert()… but delete() seems to remove the content in the InterestedTopics as well, instead of only removing a record in the pivot table…

Is there any way to achieve this. Thanks thanks.

Pass an array to your save() with the attributes you want saved.


if($model->save($false, array('field1','field2'))


Also see ‘saveAttributes’ if that applies to your situation.

Thank you very much waitforit.

By specifying the attributes when calling the method save(), i supposed this is a way to select wt fields to be altered when saving a record?

But that’s kinda different from my case… wt i mean is I have both a Reader model and an InterestedTopics model, and i’m NOT to change anything from these two models. Instead, i only want to change a record in the pivot table (reader_id, topic_id), and among all the records that could exist in the pivot table, i only want to change one.

Sorry for not making myself clear and thx for your help waitforit!!

Does anyone has any good suggestions for this problem??