#4712: Containable: ability to strictly filter returned data
-------------------------------------------+--------------------------------
Reporter: teknoid | Owner:
Type: Enhancement | Status: new
Priority: Medium | Milestone: 2.0.0.x
Component: Components | Version: 2.0.x.x
Severity: Normal | Resolution:
Keywords: containable filter teknoid | Php_version: n/a
Cake_version: |
-------------------------------------------+--------------------------------
Comment (by Dieter_be):
I agree, we should have a solution for this. (also a quite interesting
problem, technically speaking)[[BR]]
[[BR]]
I also found https://trac.cakephp.org/ticket/5834 where, if I understand
correctly they say something like this should already work.[[BR]]
Eg in this use case you should "upgrade" the condition from a contain
condition on the Account model, to a condition on the User
model.[[BR]][[BR]]
I have a similar use case, though with a longer chain of
associations.[[BR]]
I have: A->B->C->D->E->F->G and I want G.name IN ('a','b').[[BR]]
when I do:
{{{
$this->paginate['A'] = array('contain'=>array('B' => array ('C' => array
('D' => array ('E' => array ('F' => array ('G' =>
array('conditions'=>array('G.name'=> array('a','b'))))))))));
}}}
I get all A/B/C/D/E/F's with any G's if they match the conditions.[[BR]]
What I want is only the A/B/C/D/E/F's that have at least one matching G
(eg this is the same as what you want I think)
[[BR]][[BR]]
Acorrding to #5834 it should be possible by moving the G condition to the
A model, so I tried:
{{{
$this->paginate['A'] = array('conditions'=>array('G.name'=>
array('a','b')),
'contain'=>array('B' => array ('C' => array
('D' => array ('E' => array ('F' => array ('G')))))));
}}}
This gives me:[[BR]]
SELECT COUNT(*) AS "count" FROM "as" AS "A" WHERE "G"."name" IN ('a',
'b');[[BR]]
(why does cake generate a query without joins here, and why a
count?)[[BR]]
ERROR: missing FROM-clause entry for table "G"[[BR]]
[[BR]]
{{{
$this->paginate['A'] =
array('contain'=>array('conditions'=>array('G.name'=> array('a','b')),
'B' => array ('C' => array
('D' => array ('E' => array ('F' => array ('G')))))));
}}}
This does not generate a query, instead cake warns me:[[BR]]
Model "A" is not associated with model "conditions"
[CORE/cake/libs/model/behaviors/containable.php, line 340][[BR]]
ContainableBehavior::containments() -
CORE/cake/libs/model/behaviors/containable.php, line 340[[BR]]
ContainableBehavior::beforeFind() -
CORE/cake/libs/model/behaviors/containable.php, line 118[[BR]]
ModelBehavior::dispatchMethod() - CORE/cake/libs/model/behavior.php, line
160[[BR]]
BehaviorCollection::trigger() - CORE/cake/libs/model/behavior.php, line
456[[BR]]
Model::find() - CORE/cake/libs/model/model.php, line 1946[[BR]]
Controller::paginate() - CORE/cake/libs/controller/controller.php, line
1063[[BR]]
--
Ticket URL: <https://trac.cakephp.org/ticket/4712#comment:5>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---