preamble: a few days ago I asked a question to solve a HABTM-filter, I'm not able to do it even with tutorials, so "Obi Kwan Kenobi youre my only hope".
What I want to achieve: Filtering Staff by GroupID which is used in StaffStaffgroup
I'm having the following tablelayout
- staffs (a person can belong to many groups)
- staff_staffgroups (HABTM-linking table)
- staffgroups (has a groupname)
The variable $tmp gets me a working array, but the problem is that Staff is a child object of StaffStaffgroups. I could parse throu and reassemble a array, but this isnt a nice solution. So I want to use the condition on Staff (see comented line) but then I get the error 1054 "column not found: 1054 Unknown column". I tried to bind and unbind, but no result there.
$group_id = 2;
$tmp = $this->Staff->StaffStaffgroup->find('all',
array('conditions' => array(
'StaffStaffgroup.staffgroup_id' => $group_id,
'Staff.isActive =' => "1",
'Staff.last_name LIKE' => "%$name%",
)
)
);
debug($tmp);
//$tmpConditions['AND'][] = array('StaffStaffgroup.staffgroup_id' => $group_ids);
EDIT:
I tried it with conditions and containable behaviour, but unfortunatelly its not filtering anything at all
$this->Staff->contain(array('StaffStaffgroup'));
$this->paginate = array('StaffStaffgroup' =>array(
array('conditions' => array(
'StaffStaffgroup.staffgroup_id' => '2'
)
)
)
);
- I added to all models: public $actsAs = array('Containable');
I tried also with an inner join but no filtering there:
$this->paginate = array( 'conditions' => array('StaffStaffgroup.staffgroup_id' => 2 ), 'joins' => array( array( 'alias' => 'StaffStaffgroup', 'table' => 'staff_staffgroups', 'type' => 'INNER', 'conditions' => 'StaffGroup_id = StaffStaffgroup.staffgroup_id' ) )
);