this could be successfully used for Statistical queries without setters getters method, and is actually faster and could potentially used for other generator queries as well
class WhateverCount extends \yii\db\ImmutableActiveRecord
{
public function query()
{
return (new \yii\db\Query())->select(['related_id', 'counted' => 'count(*)'])->from('tablename')->groupBy('related_id'); //OR SOMETHING
}
}
class WhateverModel extends \yii\db\ActiveRecord
{
public function tablename()
{
return 'sometable';
}
public function getWhateverCount()
{
$this->hasOne(WhateverCount::class,['id'=>'related_id']);
}
}
WhateverModel::find()->with('whateverCount')->all();
would do queries like this then
SELECT * FROM sometable;
SELECT related_id, count(*) counted FROM tablename WHERE related_id IN (...) GROUP BY related_id
it would give opportunity to do things like this
WhateverModel::find()->with([
'whateverCount'=>function($query) {
$query->andWhere(['>','created_at','2013-02-14 3:22:17']
}
])->all();
And gridview would also like this :)
this could be successfully used for Statistical queries without setters getters method, and is actually faster and could potentially used for other generator queries as well
would do queries like this then
it would give opportunity to do things like this
And gridview would also like this :)