many_many relationships

I have a problem, that I have to define many to many relationships, but I don’t want get all related records.

class Post extends CActiveRecord{

public function relations()


return array(

‘tags’=>array(self::MANY_MANY, ‘Tag’, ‘{{tag_post}}(postId, tagId)’),


In table tag I have field lng and for one Post there is tags with different language.

How can I define relationship to get only tags who has lng ‘en’ ?

check this:

You can add ‘condition’ parameter to your relation.

‘tags’=>array(self::MANY_MANY, ‘Tag’, ‘{{tag_campaign}}(campaignId, tagId)’, ‘on’=>“tags.lng=‘en’”),

now it works, but how can I pass this parameter from Model, for example:


same link as in previous post… +

use ‘params’ to bind values to placeholders.

I’d use a parameterized named scope myself.

You’ll need to have a read of that and the bit it links too.