A
A
Alexey Nikolaev2015-11-02 17:12:41
Yii
Alexey Nikolaev, 2015-11-02 17:12:41

Is it possible to pass a parameter to CDBCriteria->addInCondition via a placeholder?

Good evening.
I'm trying to create a query with an IN condition using ActiveRecord. Did it like this:

$criteria = new CDbCriteria();
$criteria->select = 'alias';
$criteria->addInCondition('id', $ids); // $ids - массив с ID

This works, but I would like to pass an array through the placeholder. However, if you write something like this:
$criteria = new CDbCriteria();
$criteria->select = 'alias';
$criteria->addInCondition('id', ':ids');
$criteria->params = [
     ':ids' => $ids
];

Yii will throw an error stating that the parameter passed to addInCondition is not an array. I do not want to omit the use of the placeholder in this case - is it possible to do it in a good way? ..
I would be grateful for the advice, thanks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-11-02
@Heian

Well, everything seems to be written in the
Documentation .
You can not do it this way. Well, I want to get out, write in SQL and add all the placeholders there manually. well that's just the point...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question