开发者

how to set multi hasMany connection between model?

im using doctrine-project

and i have 3 tables

table 1: post
--------------
postid , title , date , some more fields....


table 2: tags
---------------
tagid , title


table3: post_tags 
--------------------
post_tags_id , tagid , postid

table 3 is link between tags and posts which mean each post get tags through post_tags

now in base Post model i have :

     $this->hasMany('PostTags as TagLink', array(
            'refClass' => 'PostTags',
            'local' => 'postid',
            'foreign' => 'postid'
        )

    );

which links the model to PostsTags model

and in PostsTags model i have assc "belongs to" to Post model and Tag model

now im runing the query :

$q = Doctrine::getTable('posts')->findAll();

now if 开发者_如何学编程i want to get tags i do $q->PostsTags->Tags

but i dont really care about PostsTags becouse its only link

so i want to do just

$q->Tags

and getting taglist for the post

how can i do that ?


Doctrine Using Many-to-many

Doctrine Defining Many-to-many

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜