I have a table called group_joins: Fields for the table above, like,
1)id, 2)group_id, 3)user_id, 4)created
And two more tables - these are users and user_groups, group_id a link to the primary key of the user_groups table and a user_id link to the primary key of the user table.
Now I have created a model called GroupJoin, and I want to link the table above the two tables (users, user_groups) with group_joins so that I can get all the users who joined this group.
I pass group_id to the action as a parameter. And I need all users to belong to this group.
My model is as follows:
var $belongsTo = array( 'UserGroup' => array( 'className' => 'UserGroup', 'foreignKey' => 'group_id' ) ); var $hasMany = array( 'User' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'conditions' => '', ) );
And in my controller, the query looks like this:
$groupArrs = $this->GroupJoin->find('all',array('conditions'=>'GroupJoin.group_id ="'. $group_id.'"'));
but it shows an SQL error: 1054: Unknown column "User.user_id" in the "list of fields"
then how can I get all the users that belong to this group.
source share