Cakephp "joins" destroys conditions?
A bug has a state and hasandbelongs to many usergroups among other things.
Now, when listing the bugs I used the pagination helper and also give the user the ability to filter it by various setting. Works great so far. You can filter it by project, you can filter it by state (via the state_id property of the bug) and by several other items. Now I want it to be filtered by the groups that are responsible for the bug.
Since this is a HABTM connection I used "joins" to connect up the tables.
This is what my $this->paginate looks like:
[limit] => 10
[contain] => Array
(
[0] => Project
[1] => User
[2] => Priority
[3] => State
[Comment] => Array
(
[0] => User
)
[4] => Screenshot
[5] => Group
)
[conditions] => Array
(
[Bug.project_id] => 26
[Bug.state_id] => 1
)
[Bug] => Array
(
[joins] => Array
(
[0] => Array
(
[table] => bugs_groups
[alias] => BugsGroups
[type] => inner
[conditions] => Array
(
[0] => BugsGroups.bug_id = Bug.id
开发者_如何学编程 )
)
[1] => Array
(
[table] => groups
[alias] => Group
[type] => inner
[conditions] => Array
(
[0] => Group.id = BugsGroups.group_id
[Group.id] => 9
)
)
)
)
The strange thing is - as soon as I look for a Group by using the "join" the previous conditions (project_id, state_id) are completely ignored?! Is this expected behavior in cake and how would I circumvent it?
Shouldn't these:
[0] => BugsGroups.bug_id = Bug.id
[0] => Group.id = BugsGroups.group_id
Look like:
[BugsGroups.bug_id] => Bug.id
[Group.id] => BugsGroups.group_id
?
Colleague found the solution - putting the joins inside the "Bug" key was the problem. Moving it one step up ($this->paginate['joins'] instead of $this->paginate['Bug']['joins']) makes it work beautifully...
精彩评论