Sunday, December 27, 2009

Re: Pagination with 2nd order recursive conditions filter

Hi John,

Thanks for helping but still no luck. I get this (expected) error :

Warning (512): SQL Error: 1054: Unknown column 'User.parent_id' in
'where clause' [/Users/thomas/Sites/Cake/1.2.5/cake/libs/model/
datasources/dbo_source.php, line 525]

Query: SELECT COUNT(*) AS `count` FROM `campaigns` AS `Campaign` LEFT
JOIN `user_campaigns` AS `UserCampaign` ON (`Campaign`.`id` =
`UserCampaign`.`id`) WHERE `User`.`parent_id` = 204

Query: SELECT `Campaign`.`id`, `Campaign`.`name`,
`Campaign`.`description`, `Campaign`.`active` FROM `campaigns` AS
`Campaign` LEFT JOIN `user_campaigns` AS `UserCampaign` ON
(`Campaign`.`id` = `UserCampaign`.`id`) WHERE `User`.`parent_id` = 204
ORDER BY `Campaign`.`id` asc LIMIT 20


The real problem is : is it possible with Cake to filter a model with
a condition under a related model, and how to do that?

On Dec 26, 5:15 pm, John Andersen <j.andersen...@gmail.com> wrote:
> Try to just specify:
>
> $this->Campaign->recursive = 3;
> $filter = array('User.parent_id = ' => 204); /* Changed this */
> $campaigns = $this->paginate(null, $filter);
>
> Enjoy,
>    John
>
> On Dec 19, 3:43 am,thomaus<tho...@saimiris.com> wrote:
>
> > Hi,
>
> > I have to do a 2nd order filter por pagination.
>
> > My pagination var:
>
> > var $paginate = array(
> >         'limit' => 10,
> >         'fields' => array('Campaign.id', 'Campaign.name',
> > 'Campaign.description'),
> >         'order' => array(
> >             'Campaign.id' => 'asc'),
> > );
>
> > My controller function:
>
> > $this->Campaign->recursive = 2;
> > $filter = array('UserCampaign.id = ' => 2);
> > $campaigns = $this->paginate(null, $filter);
> > pr($campaigns);
>
> > This works great and outputs this:
>
> > Array
> > (
> >     [0] => Array
> >         (
> >             [Campaign] => Array
> >                 (
> >                     [id] => 2
> >                     [name] => Newsletter
> >                     [description] => Newsletter campaign
> >                 )
>
> >             [UserCampaign] => Array
> >                 (
> >                     [id] => 2
> >                     [user_id] => 204
> >                     [campaign_id] => 2
> >                     [User] => Array
> >                         (
> >                             [id] => 204
> >                             [parent_id] => 0
> >                             [username] => barça
> >                             [fname] => Thomas
> >                         )
>
> >                     [Campaign] => Array
> >                         (
> >                             [0] => Array
> >                                 (
> >                                     [id] => 2
> >                                     [name] => Newsletter
> >                                     [description] => Newsletter
> > campaign
> >                                     [active] =>
> >                                     [created] =>
> >                                     [modified] =>
> >                                 )
>
> >                         )
>
> >                 )
>
> >         )
>
> > )
>
> > Now the problem is that I want and I need to write something like
> > this:
>
> > $this->Campaign->recursive = 3;
> > $filter = array('UserCampaign.User.parent_id = ' => 204);
> > $campaigns = $this->paginate(null, $filter);
> > pr($campaigns);
>
> > and this outputs:
>
> > Warning (512): SQL Error: 1054: Unknown column
> > 'UserCampaign.User.parent_id' in 'where clause'
>
> > which is only logical.
>
> > But then my question is : what do I have to write to get a pagination
> > with a condition based on 2nd recursive order???
>
> > Thanks in advance.

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 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

No comments: