Commit e8c6bb51 by Qiang Xue

Fixes #4048: Added `init` event to `ActiveQuery` classes

parent ab9d9063
......@@ -77,6 +77,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';
/**
* Constructor.
......@@ -90,6 +95,18 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
/**
* 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);
}
/**
* Creates a DB command that can be used to execute this query.
* @param Connection $db the DB connection used to create the DB command.
* If null, the DB connection returned by [[modelClass]] will be used.
......
......@@ -7,6 +7,7 @@
namespace yii\elasticsearch;
use Yii;
use yii\base\InvalidCallException;
use yii\base\InvalidConfigException;
use yii\db\BaseActiveRecord;
......@@ -71,7 +72,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function find()
{
return new ActiveQuery(get_called_class());
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**
......
......@@ -8,6 +8,7 @@ Yii Framework 2 elasticsearch extension Change Log
- Bug #4187: Elasticsearch dynamic scripting is disabled in 1.2.0, so do not use it in query builder (cebe)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #3527: Added `highlight` property to Query and ActiveRecord. (Borales)
- Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
- Enh: Make error messages more readable in HTML output (cebe)
- Chg: asArray in ActiveQuery is now equal to using the normal Query. This means, that the output structure has changed and `with` is supported anymore. (cebe)
......
......@@ -64,6 +64,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';
/**
* Constructor.
......@@ -77,6 +82,18 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
/**
* 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);
}
/**
* @inheritdoc
*/
protected function buildCursor($db = null)
......
......@@ -7,6 +7,7 @@
namespace yii\mongodb;
use Yii;
use yii\base\InvalidConfigException;
use yii\db\BaseActiveRecord;
use yii\db\StaleObjectException;
......@@ -96,7 +97,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*/
public static function find()
{
return new ActiveQuery(get_called_class());
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**
......
......@@ -9,6 +9,7 @@ Yii Framework 2 mongodb extension Change Log
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #3778: Gii generator for Active Record model added (klimov-paul)
- Enh #3947: Migration support added (klimov-paul)
- Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
- Enh #4335: `yii\mongodb\log\MongoDbTarget` log target added (klimov-paul)
......
......@@ -40,6 +40,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';
/**
* Constructor.
......@@ -53,6 +58,18 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
/**
* 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 \yii\mongodb\Connection $db the Mongo connection used to execute the query.
* If null, the Mongo connection returned by [[modelClass]] will be used.
......
......@@ -7,6 +7,7 @@
namespace yii\mongodb\file;
use Yii;
use yii\base\InvalidParamException;
use yii\db\StaleObjectException;
use yii\web\UploadedFile;
......@@ -49,7 +50,7 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
*/
public static function find()
{
return new ActiveQuery(get_called_class());
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**
......
......@@ -77,6 +77,10 @@ class ActiveQuery extends Component implements ActiveQueryInterface
use ActiveQueryTrait;
use ActiveRelationTrait;
/**
* @event Event an event that is triggered when the query is initialized via [[init()]].
*/
const EVENT_INIT = 'init';
/**
* Constructor.
......@@ -90,6 +94,18 @@ class ActiveQuery extends Component implements ActiveQueryInterface
}
/**
* 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 the query and returns all results as an array.
* @param Connection $db the database connection used to execute the query.
* If this parameter is not given, the `db` application component will be used.
......
......@@ -7,6 +7,7 @@
namespace yii\redis;
use Yii;
use yii\base\InvalidConfigException;
use yii\db\BaseActiveRecord;
use yii\helpers\Inflector;
......@@ -53,7 +54,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function find()
{
return new ActiveQuery(get_called_class());
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**
......
......@@ -5,6 +5,7 @@ Yii Framework 2 redis extension Change Log
--------------------------
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
......
......@@ -86,6 +86,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface
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()]].
*/
......@@ -104,6 +109,18 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
/**
* 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);
}
/**
* Sets the [[snippetCallback]] to [[fetchSnippetSourceFromModels()]], which allows to
* fetch the snippet source strings from the Active Record models, using method
* [[ActiveRecord::getSnippetSource()]].
......
......@@ -140,7 +140,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*/
public static function find()
{
return new ActiveQuery(get_called_class());
return Yii::createObject(ActiveQuery::className(), [get_called_class()]);
}
/**
......
......@@ -7,6 +7,7 @@ Yii Framework 2 sphinx extension Change Log
- Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul)
- Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `phpTypecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe)
......
......@@ -130,6 +130,7 @@ Yii Framework 2 Change Log
- Added note about the fact that intl is required for non-latin languages to requirements checker.
- Enh #3992: In mail layouts you can now access the message object via `$message` variable (qiangxue)
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue)
- Enh #4072: `\yii\rbac\PhpManager` adjustments (samdark)
- Data is now stored in three separate files for items, assignments and rules. File format is simpler.
- Removed `authFile`. Added `itemFile`, `assignmentFile` and `ruleFile`.
......
......@@ -73,6 +73,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface
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()]].
*/
......@@ -103,6 +108,18 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
/**
* 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.
* If null, the DB connection returned by [[modelClass]] will be used.
......
......@@ -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()]);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment