Unfortunately using Containable did not work as I would have hoped.

1. I could not get containable to do an inner join on the data. This is
because the actual relationships between the Book, Category and Author
tables are many-to-many so it performs a search on the books then a
search on the authors of those filtered books whereas I want the books
that contain the text and any books whose author names contain the text.
In my overridden paginate function, I break the many-to-many
relationship, make it a one-to-many and tell it to do an inner join,
giving me the data that I want. In the long run this 'sledgehammer'
approach is probably more efficient as I am doing what I want in two
calls rather than coercing Containable to behave as I want it to through
some contrived array settings in my controller.

2. The paginateCount does not use fields it seems that it does a 'select
count(*) as count' so my usage of DISTINCT in the selection ( because a
book can be in more than one category so could be duplicated ) is lost
making the paginateCount return a different value than the number of
records returned by the select.


On Tue, 2011-01-25 at 14:35 -0500, cricket wrote:
> On Tue, Jan 25, 2011 at 9:00 AM, Steve <[email protected]> wrote:
> > I have solved this by overriding the paginate and paginateCount methods
> > in my Book model.
> 
> Instead of that, you could use Containable.
> 
> And you don't need to have the else block in the index action. Declare
> $paginate as a class var, then add the 'conditions' array when
> required.
> 
> public $paginate = array(
>       'limit' => 12,
>       'order' => array('Book.created' => 'desc'),
>       'contain' => array('Author')
> );
> 
> function index()
> {
>       $this->Book->recursive = 1;
>       
>       if ($this->search)
>       {
>               $this->paginate['conditions'] = 
> $this->Book->searchConditions($this->search));
>       }
> 
>       $this->set('books', $this->paginate('Book'));
> }
> 


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