OK I did it.

On Jan 22, 9:00 pm, mmamedov <[email protected]> wrote:
> Could you elaborate on that. I tried a few things with no luck.
>
> On Jan 22, 7:30 pm, cricket <[email protected]> wrote:
>
> > On Sat, Jan 22, 2011 at 7:47 PM, mmamedov <[email protected]> wrote:
> > > I need to run this query in $this->paginate(). 99 is an arbitrary user
> > > id number that is externally provided.
>
> > > I read this, http:book.cakephp.org/view/249/Custom-Query-Pagination,
> > > but it didn't help. I did also read this http:www.littlehart.net/
> > > atthekeyboard/2008/03/04/custom-cakephp-12-pagination-queries/, and
> > > other similar posts, but they won't work for me. Because in my
> > > controller I only need this custom pagination for a single action, all
> > > other actions of the same controller work with default cakephp
> > > settings. IF I override paginate() then I'll end up messing up my
> > > other actions - because I will also need to override paginateCount()
> > > with my custom sql, something that will make my pagination in other
> > > actions useless. I love cake, but stuff like this sometimes makes you
> > > frustrated.. why they didn't provide such a basic functionality. I
> > > also couldn't find in the book.cakephp.org a way of how to create
> > > Union queries. go figure.
>
> > > What do you suggest i do?
>
> > > SELECT *
> > > FROM users
> > > WHERE users.id
> > > IN (
> > > SELECT friends.friend_id AS id
> > > FROM friends
> > > WHERE friends.user_id =99
> > > AND friends.status =1
> > > UNION
> > > SELECT friends.user_id AS id
> > > FROM friends
> > > WHERE friends.friend_id =99
> > > AND friends.status =1
> > > )
>
> > You can pass conditions in Controller::paginate(). It's the 2nd param,
> > $scope. This is merged with the $paginate class var conditions and
> > passed as the 1st param to both Model::paginate() & paginateCount().
>
> > So, in this particular action, pass as the 2nd param, eg.
> > array('union' => true) to Controller::paginate(). Override both
> > Model::paginate() and paginateCount() ...
>
> > if (isset($conditions['union']))
> > {
> >         unset($conditions['union']);
> >         // do what you need to do for your union query}
>
> > else
> > {
> >         return parent::paginate($conditions, $fields, $order, $limit, $page,
> > $recursive, $extra);
> >         // or parent::paginateCount($conditions, $recursive, $extra);
>
> > }
>
> > Untested but seems to me like the way to go.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to