Hi everybogy!
I’m trying to delete some records, using a criteria and the deleteAll function, but I’m facing two different problems…
- With no table alias:
$cri = new CDbCriteria;
if ($users !== '') {
$cri->condition = 'project_id = :project_id and user_id != :user_id AND user_id NOT IN (:users )';
$cri->params = array(':project_id' => $this->project_id, ':user_id' => 1, ':users' => $users);
} else {
$cri->condition = 'project_id = :project_id and user_id != :user_id';
$cri->params = array(':project_id' => $this->project_id, ':user_id' => user()->id);
}
ProjectUser::model()->deleteAll($cri);
In this case, no delete is executed… I don’t know why… or what I’m doing wrong, but I don’t see any deletes in my log file… Am I doing it right?
- If I do the same, but using an alias, I get a sql error:
$cri = new CDbCriteria;
$cri->alias = 'pu';
if ($users !== '') {
$cri->condition = 'pu.project_id = :project_id and pu.user_id != :user_id AND pu.user_id NOT IN (:users )';
$cri->params = array(':project_id' => $this->project_id, ':user_id' => 1, ':users' => $users);
} else {
$cri->condition = 'pu.project_id = :project_id and pu.user_id != :user_id';
$cri->params = array(':project_id' => $this->project_id, ':user_id' => user()->id);
}
ProjectUser::model()->deleteAll($cri);
In this case I have noticed that the alias ‘pu’ is not written in the query after the column name… is this a bug, or just is not allowed to use aliases on deletes?
Thank you very much in advance!