什麼是警予1.x中加入IN條件到活動查詢 你可以使用CDbCriteria這樣Yii2:活動記錄添加未在條件
$cr = new CDbCriteria();
$cr->addNotInCondition('attribute', $array);
的活動記錄的方式似乎有不等價yii2活動記錄實現中的API調用,如何通過活動記錄執行此操作?
什麼是警予1.x中加入IN條件到活動查詢 你可以使用CDbCriteria這樣Yii2:活動記錄添加未在條件
$cr = new CDbCriteria();
$cr->addNotInCondition('attribute', $array);
的活動記錄的方式似乎有不等價yii2活動記錄實現中的API調用,如何通過活動記錄執行此操作?
那麼所有的查詢操作數似乎內yii\db\QueryInterface::Where()
現合併每個文檔 的狀況現在可以使用的東西被添加像
$query = MyModel::find()->where(['attribute'=>$array]);
的不是條件是稍有不同的格式
$query = MyModel::find()->where(['not in','attribute',$array]);
$query = MyModel::findAll(['not in ','attribute',$array]);
http://www.yiiframework.com/doc-2.0/guide-db-active-record.html
空格在'不在'中是過剩的 – Vladimir 2015-12-22 13:23:29
對於數字:
$query = MyModel::find()->where('NOT IN('.implode(',', $array).')');
對於字符串
$deleteContracts = Contract::find()
->where([
'session_id' => $session_id,
'status' => Contract::STATUS_COMPLETED
])
->andWhere(['not in', 'contract_id', $contracts])
->all();
對我來說,唯一的工作解決辦法是:
$query = MyModel::find()->where('`your-attribute` NOT IN(' . implode(',', $array) . ')')->all();
此[鏈接](http://stackoverflow.com/questions/ 31041546/how-to-use-not-equal-to-inside-a-yii2-query/32860991#32860991)可以幫助某人。 – 2016-04-07 12:32:43