{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/10016","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/10016/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/10016/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/10016/events","html_url":"https://github.com/yiisoft/yii2/issues/10016","id":113393472,"number":10016,"title":"yii\\db\\ActiveRecord executes two query for relations","user":{"login":"raminious","id":334716,"avatar_url":"https://avatars.githubusercontent.com/u/334716?v=3","gravatar_id":"","url":"https://api.github.com/users/raminious","html_url":"https://github.com/raminious","followers_url":"https://api.github.com/users/raminious/followers","following_url":"https://api.github.com/users/raminious/following{/other_user}","gists_url":"https://api.github.com/users/raminious/gists{/gist_id}","starred_url":"https://api.github.com/users/raminious/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raminious/subscriptions","organizations_url":"https://api.github.com/users/raminious/orgs","repos_url":"https://api.github.com/users/raminious/repos","events_url":"https://api.github.com/users/raminious/events{/privacy}","received_events_url":"https://api.github.com/users/raminious/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-26T16:21:42Z","updated_at":"2015-10-26T16:42:54Z","closed_at":"2015-10-26T16:42:54Z","body":"I created a simple User and Profile System, every User has one Profile\r\n\r\n##### User Schema:  \r\n\r\nid (pk) | email | password | ... |\r\n---|---------|-------------|-----\r\n58 | foo@bar | password |\r\n\r\n##### Profile Schema:  \r\n  \r\nid (pk, fk)  | gender | phone | ... |\r\n----|----------|----------|----\r\n58 | 0 | +18187678 |\r\n\r\n\r\n```php\r\n    /**\r\n     * every user has one profile\r\n     * @return \\yii\\db\\ActiveQuery\r\n     */\r\n    public function getProfile ()\r\n    {\r\n        return $this->hasOne(Profile::className(), ['id' => 'id']);\r\n    }\r\n```\r\n\r\nGet Profile from User\r\n\r\n```php\r\n        $user = User::find()\r\n            ->select(['user.*', 'user_profile.*'])\r\n            ->joinWith('profile')\r\n            ->where(['user.id' => 58])\r\n            ->one();\r\n\r\n        $profile = $user->profile;\r\n```\r\n\r\nAfter executing previous code, yii generate two Sql queries, I cant understand why the second query is generated. Is this a bug ?\r\n\r\n![image](https://cloud.githubusercontent.com/assets/334716/10734821/6306ffbe-7c1a-11e5-9024-c31cdee49bfe.png)\r\n\r\nps - I test the code with and without ``` $eagerLoading ``` and the result was same\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/151204116","html_url":"https://github.com/yiisoft/yii2/issues/10016#issuecomment-151204116","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/10016","id":151204116,"user":{"login":"samdark","id":47294,"avatar_url":"https://avatars.githubusercontent.com/u/47294?v=3","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"created_at":"2015-10-26T16:42:54Z","updated_at":"2015-10-26T16:42:54Z","body":"No, it's not a bug."}}