0

when I try to run this code, it will not change my query, the condition is just not taken:

$this->paginate = array(
    'conditions' => array(
        'campaign_id' => $this->request->data['Campaign']['campaign_id']
    )
);

$this->set('products', $this->Paginator->paginate());

the query looks like this

SELECT
    `Product`.`id`, `Product`.`campaign_id`, `Campaign`.`id`, `Campaign`.`title`, `Campaign`.`text`
FROM
    `db`.`products` AS `Product`
    LEFT JOIN
        `db`.`campaigns` AS `Campaign` ON (`Product`.`campaign_id` = `Campaign`.`id`)
WHERE
    1 = 1
LIMIT
    20

Is there anything wrong in my syntax?

(CakePHP 2.5.1)

ndm
  • 59,784
  • 9
  • 71
  • 110
user1555112
  • 1,897
  • 6
  • 24
  • 43
  • The "syntax" is ok, even though you'd better use `PaginatorComponent::$settings` instead of `Controller::$paginate`, and in the conditions `Product.campaign_id`. However it should work, so there's nothing anyone can do from here other than guessing... you'll have to do further debugging on your own. – ndm Jul 03 '14 at 21:09

1 Answers1

1

What @ndm means is replace your existing code with this:

$this->Paginator->settings['conditions'] = array(
    'Product.campaign_id' => $this->request->data['Campaign']['campaign_id']
)
$this->set('products', $this->Paginator->paginate());
joshua.paling
  • 13,762
  • 4
  • 45
  • 60