MetaYii
(Metayii Framework)
1
Hi, I need to delete a bunch of records, using strings as the keys, which come in an array, for instance:
array(‘apple’, ‘blahblah’, ‘johny’);
So, I need to delete the 3 records, and I’d like to do it this way:
$keys = array(‘apple’, ‘blahblah’, ‘johny’);
$criteria = new CDbCriteria();
$criteria->condition = ‘names IN (:keys)’;
$criteria->params = array(’:keys’ => $keys);
MyActiveRecordModel::model()->deleteByPk($criteria);
But it doesn’t work. I’ve tested with integers as keys, and it works.
befi
(Bernhard Finkbeiner)
2
You would need to use addInCondition:
http://www.yiiframework.com/doc/api/1.1/CDbCriteria/#addInCondition-detail
$keys = array('apple', 'blahblah', 'johny');
$criteria = new CDbCriteria();
$criteria->addInCondition('names', $keys);
MyActiveRecordModel::model()->deleteAll($criteria);
MetaYii
(Metayii Framework)
3
Puf, I totally missed this one. Thanks a lot.