itpg
(Aigars Muiznieks)
1
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’ ?
sidewinder
(Adam Klosiu)
2
itpg
(Aigars Muiznieks)
3
‘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:
Post::model()->findAll($criteria);
sidewinder
(Adam Klosiu)
4
same link as in previous post… + http://www.yiiframework.com/doc/guide/1.1/en/database.dao#binding-parameters
use ‘params’ to bind values to placeholders.
l.jurgs
(L Jurgs)
5
I’d use a parameterized named scope myself.
http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-named-scopes
You’ll need to have a read of that and the bit it links too.