Cakephp bug:在paginator连接中生成查询

时间:2014-04-16 06:30:16

标签: php mysql sql cakephp pagination

当下面的代码在联接查询

中生成带单引号的查询时
$this->Paginator->settings = array(
            'joins' => array(
                array(
                  'table' => 'businesses_categories',
                  'alias' => 'BusinessesCategory',
                  'type' => 'LEFT',
                  'conditions' => array('Business.id' => 'BusinessesCategory`.`business_id'),
                ),
                array(
                  'table' => 'categories',
                  'alias' => 'Category',
                  'type' => 'LEFT',
                  'conditions' => array('BusinessesCategory.category_id' => 'Category.id'),
              ),
            ),
            'conditions' => array(
                'Category.id' => 24),
            'limit' => 10
        );

        $businesses = $this->Paginator->paginate('Business');

我添加了由上面的paginator查询生成的查询。查询工作正常,当我使用ON(Businessid = BusinessesCategorybusiness_id)而不是ON(Businessid =' BusinessesCategory . business_id')

我该如何解决这个问题。所以,它不包括值的单引号

SELECT `Business`.`id`,
       `Business`.`state`,
       `Business`.`slug`,
       `Business`.`city`,
       `Business`.`suburb`,
       `Business`.`user_id`,
       `Business`.`business_name`,
       `Business`.`business_address`,
       `Business`.`business_postal`,
       `Business`.`business_postal_id`,
       `Business`.`business_phone`,
       `Business`.`business_phone1`,
       `Business`.`business_phone2`,
       `Business`.`business_email`,
       `Business`.`business_website`,
       `Business`.`business_details`,
       `Business`.`business_openinghours`,
       `Business`.`business_service`,
       `Business`.`business_addtionalinfo`,
       `Business`.`business_lat`,
       `Business`.`business_lng`,
       `Business`.`identity`,
       `Business`.`status`
FROM `yuldicom`.`businesses` AS `Business`
LEFT JOIN `yuldicom`.`businesses_categories` AS `BusinessesCategory` ON (`Business`.`id` = 'BusinessesCategory`.`business_id')
LEFT JOIN `yuldicom`.`categories` AS `Category` ON (`BusinessesCategory`.`category_id` = 'Category.id')
WHERE `Category`.`id` = 24 LIMIT 10

1 个答案:

答案 0 :(得分:0)

在这里: -

    $this->Paginator->settings = array(
        'joins' => array(
            array(
              'table' => 'businesses_categories',
              'alias' => 'BusinessesCategory',
              'type' => 'LEFT',
              'conditions' => array('Business.id=BusinessesCategory.business_id'),
            ),
            array(
              'table' => 'categories',
              'alias' => 'Category',
              'type' => 'LEFT',
              'conditions' => array('BusinessesCategory.category_id=Category.id'),
          ),
        ),
        'conditions' => array(
            'Category.id' => 24),
        'limit' => 10
    );

    $businesses = $this->Paginator->paginate('Business');