我有带有ID的数组,想要通过id
删除它们$membersId = array('1','2','3');
$inStatement = implode(',', $membersId);
//dont work!
TRatingMembers::model()->deleteAll(array('member_id IN (:member_id)'),
array(':member_id' => $inStatement));
如何使用一个事务删除所有行?
答案 0 :(得分:19)
$criteria = new CDbCriteria;
$criteria->addInCondition('member_id',$membersId);
TRatingMembers::model()->deleteAll($criteria);
http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addInCondition-detail
答案 1 :(得分:4)
if (!empty(membersId)) {
$memberIds = implode(', ', $membersId);
TRatingMembers::model()->deleteAll('member_id IN (' . $memberIds . ')');
}