Yii Framework Forum: Criteria For Many To Many Relationship - Yii Framework Forum

Jump to content

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

Criteria For Many To Many Relationship Rate Topic: -----

#1 User is offline   Wilbo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 06-September 13

Posted 24 September 2013 - 02:21 PM

Hi,

I'm trying to do something really simple but I can't find the answer anywhere and it must be something that people are doing all the time on most projects.

I have three tables: users, projects and users_projects. users_projects has two columns, user_id and project_id, pretty common right?

What I can't find is how to make an ActiveDataProvider to get all the projects for a given user_id.

Can someone tell me what criteria I need to include please?

Thanks in advance.
0

#2 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 24 September 2013 - 02:55 PM

Have you read the guide about relational active records?
Don't be a dick.
0

#3 User is offline   Wilbo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 06-September 13

Posted 24 September 2013 - 02:58 PM

View Postnineinchnick, on 24 September 2013 - 02:55 PM, said:



Hi, yes I did read that thankyou and I've worked out that I needed an inner join:
'criteria'=>array(
'with'=>array('userRelationName'=>array(
'on'=>'userRelationName.id='.$givenUserId,
'together'=>true,
'joinType'=>'INNER JOIN',
))),

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