Saving Data In Related Table

Hi. I have 2 tables (page and tags), and one related table page_tags. I want save data on table page_tags. But data doesn’t save.

Thank’s)




            $genreIds = array(1, 2); 

            $page = Page::model()->findByPk(16); 

            $tags = Tags::model()->findAllByPk($genreIds); 

            $page->tags = $tags;

            $page->save();




model Page

public function relations()

    {

return array(

                'tags' => array(self::MANY_MANY, 'Tags', 'page_tags(page_id, tag_id)'),

            

        );

}




model Tags

public function relations()

    {

return array(

                'tags' => array(self::MANY_MANY, 'Page', 'page_tags(tag_id, page_id)'),

            

        );

}



This is the answer:

http://www.yiiframework.com/extension/save-relations-ar-behavior/

Thank’s, but still doesn’t work. I past in Page model function behaviors and write in controller:




$page = Page::model()->findByPk(16);

$data = array(array('tag_id'=>2,'page_id'=>2),array('tag_id'=>5,'page_id'=>3));

$page->setRelationRecords('tags',$data);

$page->save();



Please help.

Who have same problem?