views:

23

answers:

2

I have two tables which are related as HABTM

Groups (id, name) Streams(id, Stream)

connecting table groups_streams(id, group_id, stream_id)

there is another model called Users which HasOne Group.

From User controller i am trying to get the streams related to the Users GRoup.

i am doing this but getting a Mysql Error

$streams = $this->User->Group->find('list', array('conditions' => array(User.group_id => 2)));

SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 2' at line 1

SQL Dump

SELECT Group.id FROM groups AS Group WHERE = 2

1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 2' at line 1

am confused :(

+1  A: 

I would rather go with:

$streams = $this->Stream->Group->find('list', array('conditions' => array('Group.id => 2));
PawelMysior
+2  A: 

You need to wrap User.group_id in quotes within your 'conditions' array:

$streams = $this->User->Group->find('list', array(
    'conditions' => array('User.group_id' => 2)
));
Daniel Wright