mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Fixes #4048: Added init event to ActiveQuery classes
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user