Re: Pagination with recursion while using loadModel
In the CakePHP Book (http://book.cakephp.org/view/1039/Associations-
Linking-Models-Together), there are several sections that you should
note:
In the end of "3.7.6.5 hasAndBelongsToMany (HABTM)" (although it
applies to all relation types), the Book states:
The same binding trick can be used to easily paginate your HABTM
models. Just one word of caution: since paginate requires two queries
(one to count the records and one to get the actual data), be sure to
supply the false parameter to your bindModel(); which essentially
tells CakePHP to keep the binding persistent over multiple queries,
rather than just one as in the default behavior. Please refer to the
API for more details.
In "3.7.6.7 Creating and Destroying Associations on the Fly", there's
an info box after the second code box:
Removing or adding associations using bind- and unbindModel() only
works for the next find operation only unless the second parameter has
been set to false. If the second parameter has been set to false, the
bind remains in place for the remainder of the request.
So you should really be executing
$this->Transactions-
>bindModel(array('belongsTo'=>array('Item'=>array('className'=>'Item'),'Mem
ber'=>array('className'=>'Member'))), false);
Rather than the bindModel()/unbindModel() methods, consider using the
ContainableBehavior. The paginate() method directly supports it (see:
http://book.cakephp.org/view/1326/Using-Containable-with-pagination),
and has other advantages as well.
On Mar 19, 3:06 am, euromark <dereurom...@googlemail.com> wrote:
> have you tried
> var $uses = array('Transaction');
>
> PS: why is your model Transactions??? and not Transaction?
>
> On 19 Mrz., 07:26, "ashok.b" <email2...@gmail.com> wrote:
>
>
>
> > Hi, In my "Reports" controller, which is just a dummy controller
> > without any actual database, I'm trying to generate a paginated view
> > of other models. For example, to generate paginated view of
> > "Transactions" model I'm doing the following:
>
> > $this->loadModel('Transactions');
> > $this->Transactions->bindModel(array('belongsTo'=>array('Item'=>array('clas sName'=>'Item'),'Mem ber'=>array('className'=>'Member'))));
>
> > $results = $this->paginate('Transactions',null,array('recursive'=>1));
>
> > But this is not giving me associated data from Items and Members. If I
> > do a
>
> > $this->Transactions->find('all',array('recursive'=>1))
>
> > I get the associated data, but not paginated. How will I get paginated
> > view which includes the associated data too?
--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home