{"action":"opened","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/11041","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/11041/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/11041/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/11041/events","html_url":"https://github.com/yiisoft/yii2/issues/11041","id":138986450,"number":11041,"title":"hasMany via two relations fails when using through ActiveRecord::find with","user":{"login":"jurgendejonge","id":4508600,"avatar_url":"https://avatars.githubusercontent.com/u/4508600?v=3","gravatar_id":"","url":"https://api.github.com/users/jurgendejonge","html_url":"https://github.com/jurgendejonge","followers_url":"https://api.github.com/users/jurgendejonge/followers","following_url":"https://api.github.com/users/jurgendejonge/following{/other_user}","gists_url":"https://api.github.com/users/jurgendejonge/gists{/gist_id}","starred_url":"https://api.github.com/users/jurgendejonge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jurgendejonge/subscriptions","organizations_url":"https://api.github.com/users/jurgendejonge/orgs","repos_url":"https://api.github.com/users/jurgendejonge/repos","events_url":"https://api.github.com/users/jurgendejonge/events{/privacy}","received_events_url":"https://api.github.com/users/jurgendejonge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-07T14:09:53Z","updated_at":"2016-03-07T14:09:53Z","closed_at":null,"body":"I have these relations:\r\n\r\npublic function getTabInstances()\r\n{\r\nreturn $this->hasMany(\\commonFiles\\models\\TabInstance::className(), ['related_id'=>'id'])\r\n->with(['tab'])\r\n->where(['related_table'=>static::tableName()]);\r\n}\r\n\r\npublic function getComponentInstances()\r\n{\r\nreturn $this->hasMany(\\commonFiles\\models\\ComponentInstance::className(), ['tab_instance_id' => 'id'])\r\n->via('tabInstances')\r\n->with(['component']);\r\n}\r\n\r\npublic function getItemInstances()\r\n{\r\nreturn $this->hasMany(\\commonFiles\\models\\ItemInstance::className(), ['tab_instance_id' => 'id'])\r\n->via('tabInstances')\r\n->with(['item'])\r\n->orderBy(['index_number' => SORT_ASC, 'item_count' => SORT_ASC]);\r\n}\r\n\r\nThen when trying to acces them via the script below:\r\n$models = \\app\\models\\FilmShoot::find(['is_active' => true])\r\n->with('filmProduction.itemInstances', 'place.translation')\r\n->all();\r\n\r\nthe count of 'itemInstances' is 0.\r\nWhen changing the script to lazy loading (removing itemInstances from with and load them in foreach loop) the result is what I expect, not 0. \r\n"}}