On Tue, Oct 19, 2010 at 4:39 AM, [email protected]
<[email protected]> wrote:
> I have the following:
>
> 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 they
> 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" it's as if part (but strangely enough not all) of the basic
> conditions are ignored. In fact, the condition for the project_id is
> still honored, but the condition for the state_id is ignored. And I
> can't seem to wrap my head around where the problem lies...
>

It doesn't make sense that you'd have [Group.id] => 9 hard-coded in
there. Is this after you've set further options inside the action?

Anyway, you can, if the controller has both models in its $uses array,
do something like:

public $paginate = array(
        'Bug' => array(
                'limit' => 10,
                'contain' => array(...),
                'joins' => array(
                        array(
                                'table' => 'bugs_groups'
                                'alias' => 'BugsGroup'
                                'type' => 'inner'
                                'conditions' => array(
                                        'BugsGroup.bug_id' => 'Bug.id'
                                )
                        ),
                        array(
                                'table' => 'groups'
                                'alias' => 'Group'
                                'type' => 'inner'
                                'conditions' => array(
                                        'Group.id' => 'BugsGroup.group_id'
                                )
                        )
                )
        ),
        'BugsGroup' => array(
                'limit' => 10,
                'contain' => array(...),
                // other info here      
        )
        
);

Then, do $data = $this->paginate('BugsGroup');

Notice that the join-model name should be BugsGroup, although the
table is bugs_groups.

Another thing (and I'm pulling this out of my arse because I've never
tried it), I think you *might* be able to include the limit and
contain options just once, at the same level as 'Bug' & 'BugsGroup'.
Try it and see what happens.

The conditions themselves you'd add to $this->paginate array from
within the action, before calling paginate(). Whether you need to add
them to $this->paginate['Bug'] or at the top level depends on whether
the above suggestion works.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"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/cake-php?hl=en

Reply via email to