Yii Framework Forum: Saving Data In Related Table - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Saving Data In Related Table Rate Topic: -----

#1 User is offline   assd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 01-February 13

Posted 04 February 2013 - 06:41 AM

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)'),
            
        );
}

0

#2 User is offline   Ziggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 14-August 12

Posted 04 February 2013 - 11:00 AM

This is the answer:

http://www.yiiframew...ns-ar-behavior/
0

#3 User is offline   assd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 01-February 13

Posted 06 February 2013 - 10:33 AM

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.
0

#4 User is offline   assd 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 01-February 13

Posted 07 February 2013 - 03:48 AM

Who have same problem?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users