{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/11646","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/11646/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/11646/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/11646/events","html_url":"https://github.com/yiisoft/yii2/pull/11646","id":157175546,"number":11646,"title":"Added dynamic alias '@alias' in ActiveQuery","user":{"login":"CedricYii","id":14201156,"avatar_url":"https://avatars.githubusercontent.com/u/14201156?v=3","gravatar_id":"","url":"https://api.github.com/users/CedricYii","html_url":"https://github.com/CedricYii","followers_url":"https://api.github.com/users/CedricYii/followers","following_url":"https://api.github.com/users/CedricYii/following{/other_user}","gists_url":"https://api.github.com/users/CedricYii/gists{/gist_id}","starred_url":"https://api.github.com/users/CedricYii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CedricYii/subscriptions","organizations_url":"https://api.github.com/users/CedricYii/orgs","repos_url":"https://api.github.com/users/CedricYii/repos","events_url":"https://api.github.com/users/CedricYii/events{/privacy}","received_events_url":"https://api.github.com/users/CedricYii/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-27T10:21:20Z","updated_at":"2016-05-28T10:35:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/yiisoft/yii2/pulls/11646","html_url":"https://github.com/yiisoft/yii2/pull/11646","diff_url":"https://github.com/yiisoft/yii2/pull/11646.diff","patch_url":"https://github.com/yiisoft/yii2/pull/11646.patch"},"body":"| Q             | A\r\n| ------------- | ---\r\n| Is bugfix?    | no\r\n| New feature?  | yes\r\n| Breaks BC?    | no\r\n| Tests pass?   | yes\r\n| Fixed issues  | #7263, #10883 \r\n\r\nThe `@alias` placeholder enables to address dynamicaly the alias of the current table name in an active query or in a relation (without knowing it in advance).\r\n\r\nExample:\r\n````php\r\nclass Order {\r\n...\r\n  public static function find()\r\n  {\r\n    return parent::find()->orderBy( '@alias.id' );\r\n  }\r\n\r\n  //relation with table COMPANY\r\n  public function getCustomer()\r\n  {\r\n    return $this->hasOne( Company::className(), ['id' => 'customerid'] )\r\n                ->andOnCondition( [ '@alias.type' => 'customer' ] );\r\n  }\r\n...\r\n}\r\n````\r\n\r\nThen\r\n````php\r\n$orders = Order::find()->alias('o');\r\n````\r\nBuild the query:\r\n````sql\r\nselect * from order o order by o.id\r\n````\r\n\r\nAnd\r\n````php\r\n$orders = Order::find()->alias('o')->joinWith('customer c');\r\n````\r\nBuild the query:\r\n````sql\r\nselect o.* from order o \r\nleft join company c on c.id = o.customerid and c.type = 'customer'\r\norder by o.id\r\n````"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/222301850","html_url":"https://github.com/yiisoft/yii2/pull/11646#issuecomment-222301850","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/11646","id":222301850,"user":{"login":"lynicidn","id":7407411,"avatar_url":"https://avatars.githubusercontent.com/u/7407411?v=3","gravatar_id":"","url":"https://api.github.com/users/lynicidn","html_url":"https://github.com/lynicidn","followers_url":"https://api.github.com/users/lynicidn/followers","following_url":"https://api.github.com/users/lynicidn/following{/other_user}","gists_url":"https://api.github.com/users/lynicidn/gists{/gist_id}","starred_url":"https://api.github.com/users/lynicidn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lynicidn/subscriptions","organizations_url":"https://api.github.com/users/lynicidn/orgs","repos_url":"https://api.github.com/users/lynicidn/repos","events_url":"https://api.github.com/users/lynicidn/events{/privacy}","received_events_url":"https://api.github.com/users/lynicidn/received_events","type":"User","site_admin":false},"created_at":"2016-05-28T10:35:48Z","updated_at":"2016-05-28T10:35:48Z","body":"where you want configure your aliases ?"}}
{"actor":{"display_login":"lynicidn"}}