Permalink
Browse files

Fixes issue 391

  • Loading branch information...
qiang.xue
qiang.xue committed Jun 22, 2009
1 parent 6f8076e commit d9d10485c54630ce74430daa5ea9f9f0b09f2f92
Showing with 7 additions and 6 deletions.
  1. +1 −0 CHANGELOG
  2. +3 −0 UPGRADE
  3. +1 −0 docs/guide/database.ar.txt
  4. +2 −6 framework/db/ar/CActiveRecord.php
View
@@ -12,6 +12,7 @@ Version 1.0.7 to be released
- Bug: yiic webapp may generate incorrect path to yii.php (Qiang)
- Bug: SQL with OFFSET generated by command builder for Oracle is incorrect (Qiang)
- Bug: yiic shell model command may fail when a foreign key is named as ID (Qiang)
+- Chg #391: defaultScope should not be applied to UPDATE (Qiang)
- New #360: Added anchor parameter to CController::redirect (Qiang)
- New #396: Improved error display when running yiic commands (Qiang)
- New: Rolled back the change about treating tinyint(1) in MySQL as boolean (Qiang)
View
@@ -12,6 +12,9 @@ for both A and B.
Upgrading from v1.0.6
---------------------
+- Default named scope will no longer be applied to INSERT, UPDATE and
+DELETE queries. It is only applied to SELECT queries. You should be aware
+of this change if you override CActiveRecord::defaultScope() in your code.
Upgrading from v1.0.5
@@ -626,5 +626,6 @@ Now, if the following method call will automatically use the query criteria as d
$contents=Content::model()->findAll();
~~~
+Note that default named scope only applies to `SELECT` queries. It is ignored for `INSERT`, `UPDATE` and `DELETE` queries.
<div class="revision">$Id$</div>
@@ -595,7 +595,8 @@ public function getDbCriteria($createIfNull=true)
}
/**
- * Returns the default named scope that should be applied to all queries implicitly for this model.
+ * Returns the default named scope that should be implicitly applied to all queries for this model.
+ * Note, default scope only applies to SELECT queries. It is ignored for INSERT, UPDATE and DELETE queries.
* The default implementation simply returns an empty array. You may override this method
* if the model needs to be queried with some default criteria (e.g. only active records should be returned).
* @return array the query criteria. This will be used as the parameter to the constructor
@@ -1603,7 +1604,6 @@ public function updateByPk($pk,$attributes,$condition='',$params=array())
$builder=$this->getCommandBuilder();
$table=$this->getTableSchema();
$criteria=$builder->createPkCriteria($table,$pk,$condition,$params);
- $this->applyScopes($criteria);
$command=$builder->createUpdateCommand($table,$attributes,$criteria);
return $command->execute();
}
@@ -1622,7 +1622,6 @@ public function updateAll($attributes,$condition='',$params=array())
Yii::trace(get_class($this).'.updateAll()','system.db.ar.CActiveRecord');
$builder=$this->getCommandBuilder();
$criteria=$builder->createCriteria($condition,$params);
- $this->applyScopes($criteria);
$command=$builder->createUpdateCommand($this->getTableSchema(),$attributes,$criteria);
return $command->execute();
}
@@ -1641,7 +1640,6 @@ public function updateCounters($counters,$condition='',$params=array())
Yii::trace(get_class($this).'.updateCounters()','system.db.ar.CActiveRecord');
$builder=$this->getCommandBuilder();
$criteria=$builder->createCriteria($condition,$params);
- $this->applyScopes($criteria);
$command=$builder->createUpdateCounterCommand($this->getTableSchema(),$counters,$criteria);
return $command->execute();
}
@@ -1659,7 +1657,6 @@ public function deleteByPk($pk,$condition='',$params=array())
Yii::trace(get_class($this).'.deleteByPk()','system.db.ar.CActiveRecord');
$builder=$this->getCommandBuilder();
$criteria=$builder->createPkCriteria($this->getTableSchema(),$pk,$condition,$params);
- $this->applyScopes($criteria);
$command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);
return $command->execute();
}
@@ -1676,7 +1673,6 @@ public function deleteAll($condition='',$params=array())
Yii::trace(get_class($this).'.deleteAll()','system.db.ar.CActiveRecord');
$builder=$this->getCommandBuilder();
$criteria=$builder->createCriteria($condition,$params);
- $this->applyScopes($criteria);
$command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);
return $command->execute();
}

0 comments on commit d9d1048

Please sign in to comment.