Finally I know why it failed when calling $this->paginate() function..
After many days googling, I find this :
http://www.sanisoft.com/blog/2008/03/03/unbindmodel-and-paginate-gotcha-in-cakephp-12/
So I must set 'false' as the second parameter for unbindModel(), and
bindModel() function. Then the paginate() function will works just fine..
Okto.Silaban.Net
On Sun, Sep 14, 2008 at 1:25 PM, Okto Silaban <[EMAIL PROTECTED]> wrote:
> This is the query generated by find() :
>
> SELECT `Post`.`title`, `Post`.`created`, `Post`.`downloaded`,
> `Post`.`description`, `Tag`.`name`, `User`.`username`, `Post`.`id` FROM
> `posts` AS `Post` LEFT JOIN `users` AS `User` ON (`Post`.`user_id` =
> `User`.`id`) INNER JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`Post_id`
> = `Post`.`id`) INNER JOIN `tags` AS `Tag` ON (`Tag`.`id` =
> `PostsTag`.`tag_id` AND `Tag`.`slug` = 'energy') WHERE 1 = 1
>
> Then this is query generated by paginate() :
>
> (1)
> SELECT COUNT(*) AS `count` FROM `Posts` AS `Post` LEFT JOIN `users` AS
> `User` ON (`Post`.`user_id` = `User`.`id`) INNER JOIN `posts_tags` AS
> `PostsTag` ON (`PostsTag`.`Post_id` = `Post`.`id`) INNER JOIN `tags` AS
> `Tag` ON (`Tag`.`id` = `PostsTag`.`tag_id` AND `Tag`.`slug` = 'energy')
> WHERE 1 = 1
>
> (2)
> SELECT `Post`.`title`, `Post`.`created`, `Post`.`downloaded`,
> `Post`.`description`, `Tag`.`name`, `User`.`username`, `Post`.`id` FROM
> `posts` AS `Post` LEFT JOIN `users` AS `User` ON (`Post`.`user_id` =
> `User`.`id`) WHERE 1 = 1 LIMIT 20
>
> ^ we can see above (1) is the same query as find() generated query, unless
> this only take the total output rows. But when it went to (2), it didn't
> checking the Tag.slug. I think, it should be the same as find() generated
> query to get the correct results.
>
> Do i need to add a special argumen when calling the paginate() function?
>
> Okto.Silaban.Net
>
>
> On Sat, Sep 13, 2008 at 8:27 PM, teknoid <[EMAIL PROTECTED]>wrote:
>
>>
>> what is the actual query you get with paginate()? how is it different
>> from the one you get with find('all')?
>>
>> On Sep 13, 8:56 am, labanux <[EMAIL PROTECTED]> wrote:
>> > Sorry, I forget one line :
>> >
>> > $key = "energy";
>> >
>> > Anyone? teknoid himself maybe...
>> >
>> > I've been looking for the solution for about 3 days or more.., but
>> > still didn't get it..
>> >
>> > On Sep 13, 11:17 am, "Okto Silaban" <[EMAIL PROTECTED]> wrote:
>> >
>> > > I have Users, Pdfs, and Tags table.
>> >
>> > > User hasMany Product
>> > > Product habtm Tag
>> > > Tag habtm Product
>> >
>> > > I'm trying to get all Product with Tag.name = "energy".
>> >
>> > > I used a modifed code from teknoid :
>> http://teknoid.wordpress.com/2008/08/06/habtm-and-join-trickery-with-...
>> >
>> > > $searchTerms = array($key);
>> >
>> > >
>> $this->Product->unbindModel(array('hasAndBelongsToMany'=>array('Tag')));
>> >
>> > > $this->Product->bindModel(array('hasOne'=>array(
>> > > 'ProductsTag'=>array(
>> > > 'foreignKey'=>false,
>> > > 'type'=>'INNER',
>> > > 'conditions'=>array('ProductsTag.Product_id =
>> > > Product.id')
>> > > ),
>> > > 'Tag'=>array(
>> > > 'foreignKey'=>false,
>> > > 'type'=>'INNER',
>> > > 'conditions'=>array('Tag.id =
>> ProductsTag.tag_id',
>> > > array('Tag.name' => $key)
>> > > )))));
>> >
>> > > I'm trying to paginate a result from relation above, I've tried this :
>> >
>> > > $this->set('products', $this->paginate('Product') );
>> >
>> > > But it returns all products, even if they Tag.name != $key..
>> >
>> > > But if try using this : $this->Product->find('all'), it returns the
>> right
>> > > values..
>> >
>> > > So, how should I paginate the result actually?
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---