Wednesday, January 29, 2014

Containable + pagination

In cakePHP 2.4.5 I have the following model:

Article belongsTo UserUpload
Article belongsTo UserTranslated
Article belongsTo Author
Article hasAndBelongsToMany Category

I want to view a category and paginate articles with authors and user_uploads:


$paginateSettings = array(
      'ArticlesCategory' => array(
        'limit' => 4,
        'recursive' => -1,
        'conditions' => array('Category.slug' => $slug, 'Article.isTranslated' => 1),
        'order' => 'Article.created desc',
        'contain' => array(
          'Category',
          'Article.Author')
    ));

    $this->Paginator->settings = $paginateSettings;
    $articles = $this->Paginator->paginate('ArticlesCategory');

Author is never loaded. The sql executed is:

SELECT `Article`.`id`, `Category`.`slug`, `Category`.`description`, `Article`.`isTranslated`, `Article`.`title_translated`, `Article`.`title`, `Article`.`abstract_translated`, `Article`.`abstract`, `Article`.`slug`, `Article`.`created`, `Article`.`alternate_translated_by`, `Article`.`url`, `Article`.`url_description`, `Article`.`year`, `Article`.`total_views`, `Category`.`id` FROM `articles_categories` AS `ArticlesCategory` LEFT JOIN `articles` AS `Article` ON (`ArticlesCategory`.`article_id` = `Article`.`id`) LEFT JOIN `categories` AS `Category` ON (`ArticlesCategory`.`category_id` = `Category`.`id`) WHERE `Category`.`slug` = 'gender' AND `Article`.`isTranslated` = '1' ORDER BY `Article`.`created` desc LIMIT 4

Why isn't there a left join with Author?

Am I missing something?

Thanks

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: