From fee2c998f80a8fc32db50d92335c3d7fd6257722 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 10 Nov 2012 07:17:25 -0800 Subject: [PATCH] updated the default value of scenarios() --- framework/base/Model.php | 11 ++++++++++- framework/db/ar/ActiveRecord.php | 12 ++++++++++++ framework/db/dao/BaseQuery.php | 2 +- framework/db/dao/DataReader.php | 8 ++++---- framework/db/dao/QueryBuilder.php | 6 +++--- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/framework/base/Model.php b/framework/base/Model.php index a7c3433..1571ae4 100644 --- a/framework/base/Model.php +++ b/framework/base/Model.php @@ -137,11 +137,20 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess * If an attribute should NOT be massively assigned (thus considered unsafe), * please prefix the attribute with an exclamation character (e.g. '!attribute'). * + * WARNING: The default implementation returns the 'default' scenario and the result of + * [[attributes()]]. This means if the model is in 'default' scenario, all + * public member variables can be massively assigned and will be validated when + * calling [[validate()]]. Make sure you override this method if you do not want + * this behavior (e.g. you only want some of the attributes to be massively assigned + * and validated.) + * * @return array a list of scenarios and the corresponding relevant attributes. */ public function scenarios() { - return array(); + return array( + 'default' => $this->attributes(), + ); } /** diff --git a/framework/db/ar/ActiveRecord.php b/framework/db/ar/ActiveRecord.php index 2cf76b5..3691571 100644 --- a/framework/db/ar/ActiveRecord.php +++ b/framework/db/ar/ActiveRecord.php @@ -594,6 +594,18 @@ abstract class ActiveRecord extends Model } /** + * Returns a list of scenarios and the corresponding relevant attributes. + * Please refer to [[\yii\base\Model::scenarios()]] for more details. + * The implementation here simply returns an empty array. You may override + * this method to return the scenarios that you want to use with this AR class. + * @return array a list of scenarios and the corresponding relevant attributes. + */ + public function scenarios() + { + return array(); + } + + /** * Returns the named attribute value. * If this is a new record and the attribute is not set before, * the default column value will be returned. diff --git a/framework/db/dao/BaseQuery.php b/framework/db/dao/BaseQuery.php index c2d5a2e..fdbfc58 100644 --- a/framework/db/dao/BaseQuery.php +++ b/framework/db/dao/BaseQuery.php @@ -67,7 +67,7 @@ class BaseQuery extends \yii\base\Component public $group; /** * @var string|array how to join with other tables. This refers to the JOIN clause in a SQL statement. - * It can either a string (e.g. `'LEFT JOIN tbl_user ON tbl_user.id=author_id'`) or an array (e.g. + * It can be either a string (e.g. `'LEFT JOIN tbl_user ON tbl_user.id=author_id'`) or an array (e.g. * `array('LEFT JOIN tbl_user ON tbl_user.id=author_id', 'LEFT JOIN tbl_team ON tbl_team.id=team_id')`). * @see join() */ diff --git a/framework/db/dao/DataReader.php b/framework/db/dao/DataReader.php index 91b2ce6..3d744f4 100644 --- a/framework/db/dao/DataReader.php +++ b/framework/db/dao/DataReader.php @@ -94,7 +94,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable /** * Advances the reader to the next row in a result set. - * @return array|false the current row, false if no more row available + * @return array the current row, false if no more row available */ public function read() { @@ -104,7 +104,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable /** * Returns a single column from the next row of a result set. * @param integer $columnIndex zero-based column index - * @return mixed|false the column of the current row, false if no more row available + * @return mixed the column of the current row, false if no more row available */ public function readColumn($columnIndex) { @@ -115,7 +115,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable * Returns an object populated with the next row of data. * @param string $className class name of the object to be created and populated * @param array $fields Elements of this array are passed to the constructor - * @return mixed|false the populated object, false if no more row of data available + * @return mixed the populated object, false if no more row of data available */ public function readObject($className, $fields) { @@ -149,7 +149,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable /** * Closes the reader. * This frees up the resources allocated for executing this SQL statement. - * Read attemps after this method call are unpredictable. + * Read attempts after this method call are unpredictable. */ public function close() { diff --git a/framework/db/dao/QueryBuilder.php b/framework/db/dao/QueryBuilder.php index a2b685f..407179e 100644 --- a/framework/db/dao/QueryBuilder.php +++ b/framework/db/dao/QueryBuilder.php @@ -92,7 +92,7 @@ class QueryBuilder extends \yii\base\Object * * @param string $table the table that new rows will be inserted into. * @param array $columns the column data (name=>value) to be inserted into the table. - * @return integer number of rows affected by the execution. + * @return string the INSERT SQL */ public function insert($table, $columns) { @@ -139,7 +139,7 @@ class QueryBuilder extends \yii\base\Object * @param mixed $condition the condition that will be put in the WHERE part. Please * refer to [[Query::where()]] on how to specify condition. * @param array $params the parameters to be bound to the query. - * @return integer number of rows affected by the execution. + * @return string the UPDATE SQL */ public function update($table, $columns, $condition = '', $params = array()) { @@ -180,7 +180,7 @@ class QueryBuilder extends \yii\base\Object * @param mixed $condition the condition that will be put in the WHERE part. Please * refer to [[Query::where()]] on how to specify condition. * @param array $params the parameters to be bound to the query. - * @return integer number of rows affected by the execution. + * @return string the DELETE SQL */ public function delete($table, $condition = '', $params = array()) {