Work With Relations Active Record

Hy. A’m sorry for my bad english. I want relate 2 tables (page and tags). i’m use relation table (page_tags). But than I want get records in view I get array(). Thank’s for help)




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

print_r ($tags=$page->tags);



This is my relations:




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

            

        );

}



Hi, welcome on forum.

Please let us know what you want to achieve ? I could be wrong but I am guessing that You want to show every tags for single page, in this scenerio You dont need MANY_MANY relation, but HAS_MANY and BELONGS_TO, but like i said its only a guess.

pls follow this forum… this gives you clear idea.

http://www.yiiframework.com/forum/index.php/topic/12637-please-explain-how-to-do-many-to-many-relationships-for-newcomer/

hope it helps you

For exemple post "Article_1" have tags "News, animals". I want get same post which have this or one of this tags.

tahnk’s, it’s help)

I have one more question. In admin page I show all tags. Than I check (use checkbox) all tags I need. How write to db (page_tags) all checking tags?