preamble: a few days ago I asked a question to solve the HABTM filter, I can’t do it even with textbooks, so "Obi Kwan Kenobi youre my only hope."
What I want to achieve: Filtering personnel by GroupID, which is used by StaffStaffgroup
I have the following tablelayout
- employees (a person can belong to many groups)
- staff_staffgroups (HABTM-linking table)
- staffgroups (has a group name)
The $ tmp variable returns me a working array, but the problem is that Staff is a child of StaffStaffgroups. I could parse and assemble the array, but this is not a good solution. So I want to use the condition for Staff (see Command Prompt), but then I get error 1054 "column not found: 1054 Unknown column". I tried to tie and untie, but there is no result.
$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 this with conditions and restrained behavior, but unfortunately it didn't filter 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 $ actAs = array ('Containable');
I tried also with the inner join, but there was no filtering:
$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'
)
)
);
source
share