{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/10459","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/10459/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/10459/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/10459/events","html_url":"https://github.com/yiisoft/yii2/issues/10459","id":123511010,"number":10459,"title":"[PROPOSAL] query as immutable activerecord object","user":{"login":"mikk150","id":4953629,"avatar_url":"https://avatars.githubusercontent.com/u/4953629?v=3","gravatar_id":"","url":"https://api.github.com/users/mikk150","html_url":"https://github.com/mikk150","followers_url":"https://api.github.com/users/mikk150/followers","following_url":"https://api.github.com/users/mikk150/following{/other_user}","gists_url":"https://api.github.com/users/mikk150/gists{/gist_id}","starred_url":"https://api.github.com/users/mikk150/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikk150/subscriptions","organizations_url":"https://api.github.com/users/mikk150/orgs","repos_url":"https://api.github.com/users/mikk150/repos","events_url":"https://api.github.com/users/mikk150/events{/privacy}","received_events_url":"https://api.github.com/users/mikk150/received_events","type":"User","site_admin":false},"labels":[{"id":33241821,"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:under%20discussion","name":"status:under discussion","color":"f7c6c7","default":false},{"id":33332028,"url":"https://api.github.com/repos/yiisoft/yii2/labels/type:enhancement","name":"type:enhancement","color":"d7e102","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/yiisoft/yii2/milestones/6","html_url":"https://github.com/yiisoft/yii2/milestones/2.1.x","labels_url":"https://api.github.com/repos/yiisoft/yii2/milestones/6/labels","id":458001,"number":6,"title":"2.1.x","description":"","creator":{"login":"qiangxue","id":993322,"avatar_url":"https://avatars.githubusercontent.com/u/993322?v=3","gravatar_id":"","url":"https://api.github.com/users/qiangxue","html_url":"https://github.com/qiangxue","followers_url":"https://api.github.com/users/qiangxue/followers","following_url":"https://api.github.com/users/qiangxue/following{/other_user}","gists_url":"https://api.github.com/users/qiangxue/gists{/gist_id}","starred_url":"https://api.github.com/users/qiangxue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiangxue/subscriptions","organizations_url":"https://api.github.com/users/qiangxue/orgs","repos_url":"https://api.github.com/users/qiangxue/repos","events_url":"https://api.github.com/users/qiangxue/events{/privacy}","received_events_url":"https://api.github.com/users/qiangxue/received_events","type":"User","site_admin":false},"open_issues":119,"closed_issues":16,"state":"open","created_at":"2013-10-17T21:06:09Z","updated_at":"2016-11-02T09:10:35Z","due_on":null,"closed_at":null},"comments":15,"created_at":"2015-12-22T16:16:53Z","updated_at":"2016-11-02T09:34:38Z","closed_at":null,"body":"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\n\n``` php\nclass WhateverCount extends \\yii\\db\\ImmutableActiveRecord\n{\n    public function query()\n    {\n        return (new \\yii\\db\\Query())->select(['related_id', 'counted' => 'count(*)'])->from('tablename')->groupBy('related_id'); //OR SOMETHING\n    }\n}\n\nclass WhateverModel extends \\yii\\db\\ActiveRecord\n{\n    public function tablename()\n    {\n        return 'sometable';\n    }\n\n    public function getWhateverCount()\n    {\n        $this->hasOne(WhateverCount::class,['id'=>'related_id']);\n    }\n}\n```\n\n``` php\nWhateverModel::find()->with('whateverCount')->all();\n```\n\nwould do queries like this then\n\n``` sql\nSELECT * FROM sometable;\nSELECT related_id, count(*) counted FROM tablename WHERE related_id IN (...) GROUP BY related_id\n```\n\nit would give opportunity to do things like this\n\n``` php\nWhateverModel::find()->with([\n    'whateverCount'=>function($query) {\n        $query->andWhere(['>','created_at','2013-02-14 3:22:17']\n    }\n])->all();\n```\n\nAnd gridview would also like this :)\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/257814910","html_url":"https://github.com/yiisoft/yii2/issues/10459#issuecomment-257814910","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/10459","id":257814910,"user":{"login":"dynasource","id":125726,"avatar_url":"https://avatars.githubusercontent.com/u/125726?v=3","gravatar_id":"","url":"https://api.github.com/users/dynasource","html_url":"https://github.com/dynasource","followers_url":"https://api.github.com/users/dynasource/followers","following_url":"https://api.github.com/users/dynasource/following{/other_user}","gists_url":"https://api.github.com/users/dynasource/gists{/gist_id}","starred_url":"https://api.github.com/users/dynasource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dynasource/subscriptions","organizations_url":"https://api.github.com/users/dynasource/orgs","repos_url":"https://api.github.com/users/dynasource/repos","events_url":"https://api.github.com/users/dynasource/events{/privacy}","received_events_url":"https://api.github.com/users/dynasource/received_events","type":"User","site_admin":false},"created_at":"2016-11-02T09:34:38Z","updated_at":"2016-11-02T09:34:38Z","body":"that sounds quite useful. Do you still think this is something for the core to adopt? Or do you see it to be more useful as a special extension?"}}
{"actor":{"display_login":"dynasource"}}