{"action":"opened","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/11446","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/11446/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/11446/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/11446/events","html_url":"https://github.com/yiisoft/yii2/issues/11446","id":151603246,"number":11446,"title":"Не работает indexBy для связанных моделей","user":{"login":"wartur","id":1358236,"avatar_url":"https://avatars.githubusercontent.com/u/1358236?v=3","gravatar_id":"","url":"https://api.github.com/users/wartur","html_url":"https://github.com/wartur","followers_url":"https://api.github.com/users/wartur/followers","following_url":"https://api.github.com/users/wartur/following{/other_user}","gists_url":"https://api.github.com/users/wartur/gists{/gist_id}","starred_url":"https://api.github.com/users/wartur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wartur/subscriptions","organizations_url":"https://api.github.com/users/wartur/orgs","repos_url":"https://api.github.com/users/wartur/repos","events_url":"https://api.github.com/users/wartur/events{/privacy}","received_events_url":"https://api.github.com/users/wartur/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-28T10:27:40Z","updated_at":"2016-04-28T10:27:40Z","closed_at":null,"body":"### What steps will reproduce the problem?\r\nИмею простые 2 таблицы, страна и город\r\n\r\nПытаюсь искать\r\n\r\n```\r\nFilterCity::find()\r\n->leftJoin('filter_country', 'filter_city.filter_country_id = filter_country.id')\r\n->select('filter_country.name')\r\n->where(['filter_city.id' => $this->index_city])\r\n->orderBy('filter_country.name')\r\n->indexBy('filter_country.id') // ОБРАЩАЕМ ВНИМАНИЕ!!!!\r\n->column();\r\n```\r\n\r\n### What is the expected result?\r\nХочу получить примерно следующее\r\n[1 => 'Россия'],\r\n\r\nВ результате получаю\r\n[0 => 'Россия']\r\n\r\n\r\n### What do you get instead?\r\nВ общем если сделать ->indexBy('id') все работает.\r\nЗапрос который я указал наверху слегка утрированный, но вот тоже самое для городов\r\n            $result = FilterCity::find()\r\n                    ->select('name')\r\n                    ->where(['filter_country_id' => $this->index_country])\r\n                    ->orderBy('name')\r\n                    ->indexBy('filter_city.id') // НЕ РАБОТАЕТ, ХОТЯ СТРАННО!!!\r\n                    ->column();\r\n\r\n            $result = FilterCity::find()\r\n                    ->select('name')\r\n                    ->where(['filter_country_id' => $this->index_country])\r\n                    ->orderBy('name')\r\n                    ->indexBy('id') // ВСЕ ПУТЕМ!\r\n                    ->column();\r\n\r\nСчитаю косяком, так как я по началу думал что он индексирует через модель поэтому пытался сделать так indexBy('FilterCity.id'), но упала база данных.\r\n\r\n### Additional info\r\nБаза данных:\r\n\r\n```\r\nSET FOREIGN_KEY_CHECKS=0;\r\nSET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\r\nSET AUTOCOMMIT=0;\r\nSTART TRANSACTION;\r\nSET time_zone = \"+00:00\";\r\n\r\n-- --------------------------------------------------------\r\n\r\n--\r\n-- Table structure for table `filter_city`\r\n--\r\n\r\nCREATE TABLE IF NOT EXISTS `filter_city` (\r\n  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n  `filter_country_id` int(11) NOT NULL COMMENT 'Страна',\r\n  `name` varchar(40) NOT NULL COMMENT 'Название города',\r\n  `slug` varchar(40) NOT NULL COMMENT 'ЧПУ',\r\n  PRIMARY KEY (`id`),\r\n  UNIQUE KEY `name` (`name`),\r\n  UNIQUE KEY `slug` (`slug`),\r\n  KEY `filter_city_ifbk_filter_country` (`filter_country_id`),\r\n) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='Фильтр города' AUTO_INCREMENT=3 ;\r\n\r\n\r\nINSERT INTO `filter_city` (`id`, `filter_country_id`, `name`, `slug`) VALUES\r\n(1, 1, 'Санкт-Петербург', 'sankt-peterburg'),\r\n(2, 1, 'Москва', 'moskva');\r\n\r\n-- --------------------------------------------------------\r\n\r\n--\r\n-- Table structure for table `filter_country`\r\n--\r\n\r\nCREATE TABLE IF NOT EXISTS `filter_country` (\r\n  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n  `name` varchar(40) NOT NULL COMMENT 'Название страны',\r\n  `slug` varchar(40) NOT NULL COMMENT 'ЧПУ',\r\n  PRIMARY KEY (`id`),\r\n  UNIQUE KEY `name` (`name`),\r\n  UNIQUE KEY `slug` (`slug`)\r\n) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='Фильтр страны' AUTO_INCREMENT=5 ;\r\n\r\n--\r\n-- Dumping data for table `filter_country`\r\n--\r\n\r\nINSERT INTO `filter_country` (`id`, `name`, `slug`) VALUES\r\n(1, 'Россия', 'rossia'),\r\n(2, 'Франция', 'francia'),\r\n(3, 'Германия', 'germania'),\r\n(4, 'Таиланд', 'tailand');\r\n\r\n--\r\n-- Constraints for dumped tables\r\n--\r\n\r\n--\r\n-- Constraints for table `filter_city`\r\n--\r\nALTER TABLE `filter_city`\r\n  ADD CONSTRAINT `filter_city_ifbk_filter_country` FOREIGN KEY (`filter_country_id`) REFERENCES `filter_country` (`id`) ON DELETE CASCADE;\r\nSET FOREIGN_KEY_CHECKS=1;\r\nCOMMIT;\r\n```\r\n\r\n| Q                | A\r\n| ---------------- | ---\r\n| Yii version      |  2.0.7\r\n| PHP version      |  5.6.16\r\n| Operating system | Windows 7"}}