Fixes #4048: Added init event to ActiveQuery classes

This commit is contained in:
Qiang Xue
2014-07-19 20:26:58 -04:00
parent ab9d906351
commit e8c6bb516f
17 changed files with 116 additions and 6 deletions

View File

@ -72,6 +72,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface
use ActiveQueryTrait;
use ActiveRelationTrait;
/**
* @event Event an event that is triggered when the query is initialized via [[init()]].
*/
const EVENT_INIT = 'init';
/**
* @var string the SQL statement to be executed for retrieving AR records.
* This is set by [[ActiveRecord::findBySql()]].
@ -102,6 +107,18 @@ class ActiveQuery extends Query implements ActiveQueryInterface
parent::__construct($config);
}
/**
* Initializes the object.
* This method is called at the end of the constructor. The default implementation will trigger
* an [[EVENT_INIT]] event. If you override this method, make sure you call the parent implementation at the end
* to ensure triggering of the event.
*/
public function init()
{
parent::init();
$this->trigger(self::EVENT_INIT);
}
/**
* Executes query and returns all results as an array.
* @param Connection $db the DB connection used to create the DB command.

View File

@ -258,7 +258,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function find()
{
return new ActiveQuery(get_called_class());
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**