Escape from CakePHP Paginate condition

Viewed 73

Paginate query:

$this->paginate = array(
            'conditions' => array(
               // 'Product.soft_delete NOT'    => 'on',
               // 'Product.product_status NOT' => 'inactive',
               // $conditions
               'Product.original_price <=' =>  77
            ),
            'recursive'  => 2,
           // 'order'      => $sort_by,
            'paramType'  => 'querystring',
            'limit'      => '25',
            'maxLimit'   => 100,
        );
        $records = $this->paginate('Product');

CakePHP adding single quote to original_price 77 so it is creating problems in number comparison.

Cakephp query output:

............LEFT JOIN `admin_mytab`.`seller_categories` AS `Seller_3` ON (`Product`.`seller_3` = `Seller_3`.`id`) WHERE `Product`.`original_price` <= '77' LIMIT 25

MySQL original_price is varchar field. 77 in quotes unable to compare with mysql field.

Any help would be appreciated.

1 Answers

Try writing it like this:

$this->paginate = array(
    'conditions' => array(
        'Product.original_price <= 77'
    ),
    'recursive' => 2,
    'paramType' => 'querystring',
    'limit' => '25',
    'maxLimit' => 100,
);
$records = $this->paginate('Product');

Instead of key => value just use value. But usually it doesn't matter if number is enclosed with quotes, even with varchar.

Related