BUG(?) Containable + HABTM: including only Model1 WHERE ... in Model2 also returns all Model1 which do not have a Model2
Scenario:
Plan HABTM Status
Plan Belongsto Department
Plan Belongsto Element
Controller code:
$data= $this->Plan->find('all', array(
'contain' => array (
'Status.name = "approved"',
'Element',
'Department'
),
'conditions' => array (
'Plan.year IN (' . $years . ')',
)
));
pr($data); die();
Output:
Array
(
[0] => Array
(
[Plan] => Array
(
[id] => 2
[plan_type_id] => 1
[department_id] => 5
[element_id] => 12
[year] => 2009
)
[Department] => Array
(
[id] => 5
[name] => DEPARTMENT 1
[created] => 2009-03-06 14:52:02
[modified] => 2009-03-06 14:52:02
)
[Element] => Array
(
[id] => 12
[parent_id] =>
[user_id] => 1
[element_type_id] => 4
[active] => 1
[value] =>
[created] => 2009-04-15 09:47:09
[modified] => 2009-04-15 09:47:09
[lft] => 1
[rght] => 12
[plan_id] => 0
)
[Status] => Array
(
)
)
[1] => Array
(
[Plan] => Array
(
[id] => 4
[plan_type_id] => 2
[department_id] => 33
[element_id] => 589
[year] => 2009
)
[Department] => Array
(
[id] => 33
[name] => DEPARTMENT 2
[created] => 2009-04-30 13:24:37
[modified] => 2009-04-30 13:24:37
)
[Element] => Array
(
[id] => 589
[parent_id] =>
[user_id] => 4949
[element_type_id] => 4
[active] => 1
[value] =>
[created] => 2009-05-11 15:13:57
[modified] => 2009-05-11 15:13:57
[lft] => 677
[rght] => 754
[plan_id] => 0
)
[Status] => Array
(
[0] => Array
(
[id] => 2
[name] => approved
[message] => All good
[PlanStatus] => Array
(
[id] => 45
[plan_id] => 4
[status_id] => 2
[created] => 2009-09-15 09:35:10
)
)
)
)
..
..
..
)
Getting the hang of writing the contain code was challenging, but it
seems to be doing ALMOST what I need now. Only problem is that it now
returns not just plans which have been approved (as with DEPARTMENT
2's plan), but also plans which have no entries in the PlanStatus
table (as with DEPARTMENT 1's plan). I tried adding the Status.name
condition to the conditions for the find, but that query just fails
because it's a HABTM. Any suggestions?
Thank you,
James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home