{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony/pulls/comments/32818798","id":32818798,"diff_hunk":"@@ -107,16 +114,21 @@ public function __construct(ObjectManager $manager, $class, $labelPath = null, E\n         $this->class = $this->classMetadata->getName();\n         $this->loaded = is_array($entities) || $entities instanceof \\Traversable;\n         $this->preferredEntities = $preferredEntities;\n+        list(\n+            $this->idField,\n+            $this->idAsIndex,\n+            $this->idAsValue\n+        ) = $this->getIdentifierInfoForClass($this->classMetadata);\n+\n+        if (null !== $this->idField && $this->classMetadata->hasAssociation($this->idField)) {\n+            $this->idClassMetadata = $this->em->getClassMetadata(\n+                $this->classMetadata->getAssociationTargetClass($this->idField)\n+            );\n \n-        $identifier = $this->classMetadata->getIdentifierFieldNames();\n-\n-        if (1 === count($identifier)) {\n-            $this->idField = $identifier[0];\n-            $this->idAsValue = true;\n-\n-            if (in_array($this->classMetadata->getTypeOfField($this->idField), array('integer', 'smallint', 'bigint'))) {\n-                $this->idAsIndex = true;\n-            }\n+            list(\n+                $this->idAsIndex,\n+                $this->idAsValue\n+            ) = array_slice($this->getIdentifierInfoForClass($this->idClassMetadata), 1);","path":"src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php","position":41,"original_position":41,"commit_id":"cde2087fba166c00ef509b45bbe8a6fa767111f1","original_commit_id":"cde2087fba166c00ef509b45bbe8a6fa767111f1","user":{"login":"giosh94mhz","id":5219975,"avatar_url":"https://avatars.githubusercontent.com/u/5219975?v=3","gravatar_id":"","url":"https://api.github.com/users/giosh94mhz","html_url":"https://github.com/giosh94mhz","followers_url":"https://api.github.com/users/giosh94mhz/followers","following_url":"https://api.github.com/users/giosh94mhz/following{/other_user}","gists_url":"https://api.github.com/users/giosh94mhz/gists{/gist_id}","starred_url":"https://api.github.com/users/giosh94mhz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giosh94mhz/subscriptions","organizations_url":"https://api.github.com/users/giosh94mhz/orgs","repos_url":"https://api.github.com/users/giosh94mhz/repos","events_url":"https://api.github.com/users/giosh94mhz/events{/privacy}","received_events_url":"https://api.github.com/users/giosh94mhz/received_events","type":"User","site_admin":false},"body":"The `array_slice` call is required (or a similar approach obviously :), since when called the second time the returned identifier is the one from the associated entity. The field name may be different in the two entities, so it is important that only the type information are carried on, without the foreign name.\r\n\r\nI can refactor the method as `initIdentifierInfoForClass`, but still I have to do something like:\r\n```\r\n$bakIdField = $this->idField;\r\n$this->initIdentifierInfoForClass($this->idClassMetadata); \r\n$this->idField = $bakIdField;\r\n```\r\nor like:\r\n```\r\n$this->initIdentifierInfoForClass($this->idClassMetadata, false); \r\n// ...\r\nprivate function getIdentifierInfoForClass(ClassMetadata $classMetadata, $initIdField)\r\n// ...\r\n```\r\nWhich one is clearer? I vote for the second one...\r\n","created_at":"2015-06-19T10:44:13Z","updated_at":"2015-06-19T10:44:13Z","html_url":"https://github.com/symfony/symfony/pull/14372#discussion_r32818798","pull_request_url":"https://api.github.com/repos/symfony/symfony/pulls/14372","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/32818798"},"html":{"href":"https://github.com/symfony/symfony/pull/14372#discussion_r32818798"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14372"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/14372","id":33441223,"html_url":"https://github.com/symfony/symfony/pull/14372","diff_url":"https://github.com/symfony/symfony/pull/14372.diff","patch_url":"https://github.com/symfony/symfony/pull/14372.patch","issue_url":"https://api.github.com/repos/symfony/symfony/issues/14372","number":14372,"state":"open","locked":false,"title":"[DoctrineBridge][Form] fix EntityChoiceList when indexing by primary foreign key","user":{"login":"giosh94mhz","id":5219975,"avatar_url":"https://avatars.githubusercontent.com/u/5219975?v=3","gravatar_id":"","url":"https://api.github.com/users/giosh94mhz","html_url":"https://github.com/giosh94mhz","followers_url":"https://api.github.com/users/giosh94mhz/followers","following_url":"https://api.github.com/users/giosh94mhz/following{/other_user}","gists_url":"https://api.github.com/users/giosh94mhz/gists{/gist_id}","starred_url":"https://api.github.com/users/giosh94mhz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giosh94mhz/subscriptions","organizations_url":"https://api.github.com/users/giosh94mhz/orgs","repos_url":"https://api.github.com/users/giosh94mhz/repos","events_url":"https://api.github.com/users/giosh94mhz/events{/privacy}","received_events_url":"https://api.github.com/users/giosh94mhz/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Bug fix?      | yes\r\n| New feature?  | no\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets |\r\n| License       | MIT\r\n| Doc PR        | \r\n\r\nI've found a bug while using the 'entity' FormType.\r\n\r\nDoctrine allow the definition of primary keys which are foreign key of other entities. In this scenario, the `EntityChoiceList` instance check if:\r\n  * the entity has a id composed by a single column and\r\n  * eventually, the column is an integer\r\n\r\nWhen this happens, it use the primary key as \"choices indices\", but since is an entity it fails in many places, where it expects integer.\r\n\r\nThe easy solution is to check whether the single-column id is not an association. Anyway, I've fixed it the RightWay™ :), and now it resolve the entity reference to the actual column type, and restart the logic. Code speaks better then words.\r\n\r\n\r\n","created_at":"2015-04-16T11:24:37Z","updated_at":"2015-06-19T10:44:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"96176f01d01b318cea784587fef1d77cdf23e836","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony/pulls/14372/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony/pulls/14372/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/14372/comments","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/cde2087fba166c00ef509b45bbe8a6fa767111f1","head":{"label":"giosh94mhz:entity_choice_list_with_primary_key_association","ref":"entity_choice_list_with_primary_key_association","sha":"cde2087fba166c00ef509b45bbe8a6fa767111f1","user":{"login":"giosh94mhz","id":5219975,"avatar_url":"https://avatars.githubusercontent.com/u/5219975?v=3","gravatar_id":"","url":"https://api.github.com/users/giosh94mhz","html_url":"https://github.com/giosh94mhz","followers_url":"https://api.github.com/users/giosh94mhz/followers","following_url":"https://api.github.com/users/giosh94mhz/following{/other_user}","gists_url":"https://api.github.com/users/giosh94mhz/gists{/gist_id}","starred_url":"https://api.github.com/users/giosh94mhz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giosh94mhz/subscriptions","organizations_url":"https://api.github.com/users/giosh94mhz/orgs","repos_url":"https://api.github.com/users/giosh94mhz/repos","events_url":"https://api.github.com/users/giosh94mhz/events{/privacy}","received_events_url":"https://api.github.com/users/giosh94mhz/received_events","type":"User","site_admin":false},"repo":{"id":13984397,"name":"symfony","full_name":"giosh94mhz/symfony","owner":{"login":"giosh94mhz","id":5219975,"avatar_url":"https://avatars.githubusercontent.com/u/5219975?v=3","gravatar_id":"","url":"https://api.github.com/users/giosh94mhz","html_url":"https://github.com/giosh94mhz","followers_url":"https://api.github.com/users/giosh94mhz/followers","following_url":"https://api.github.com/users/giosh94mhz/following{/other_user}","gists_url":"https://api.github.com/users/giosh94mhz/gists{/gist_id}","starred_url":"https://api.github.com/users/giosh94mhz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giosh94mhz/subscriptions","organizations_url":"https://api.github.com/users/giosh94mhz/orgs","repos_url":"https://api.github.com/users/giosh94mhz/repos","events_url":"https://api.github.com/users/giosh94mhz/events{/privacy}","received_events_url":"https://api.github.com/users/giosh94mhz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/giosh94mhz/symfony","description":"The Symfony PHP framework","fork":true,"url":"https://api.github.com/repos/giosh94mhz/symfony","forks_url":"https://api.github.com/repos/giosh94mhz/symfony/forks","keys_url":"https://api.github.com/repos/giosh94mhz/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/giosh94mhz/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/giosh94mhz/symfony/teams","hooks_url":"https://api.github.com/repos/giosh94mhz/symfony/hooks","issue_events_url":"https://api.github.com/repos/giosh94mhz/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/giosh94mhz/symfony/events","assignees_url":"https://api.github.com/repos/giosh94mhz/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/giosh94mhz/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/giosh94mhz/symfony/tags","blobs_url":"https://api.github.com/repos/giosh94mhz/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/giosh94mhz/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/giosh94mhz/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/giosh94mhz/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/giosh94mhz/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/giosh94mhz/symfony/languages","stargazers_url":"https://api.github.com/repos/giosh94mhz/symfony/stargazers","contributors_url":"https://api.github.com/repos/giosh94mhz/symfony/contributors","subscribers_url":"https://api.github.com/repos/giosh94mhz/symfony/subscribers","subscription_url":"https://api.github.com/repos/giosh94mhz/symfony/subscription","commits_url":"https://api.github.com/repos/giosh94mhz/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/giosh94mhz/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/giosh94mhz/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/giosh94mhz/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/giosh94mhz/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/giosh94mhz/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/giosh94mhz/symfony/merges","archive_url":"https://api.github.com/repos/giosh94mhz/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/giosh94mhz/symfony/downloads","issues_url":"https://api.github.com/repos/giosh94mhz/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/giosh94mhz/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/giosh94mhz/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/giosh94mhz/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/giosh94mhz/symfony/labels{/name}","releases_url":"https://api.github.com/repos/giosh94mhz/symfony/releases{/id}","created_at":"2013-10-30T11:14:59Z","updated_at":"2015-01-22T10:37:47Z","pushed_at":"2015-05-06T09:34:40Z","git_url":"git://github.com/giosh94mhz/symfony.git","ssh_url":"git@github.com:giosh94mhz/symfony.git","clone_url":"https://github.com/giosh94mhz/symfony.git","svn_url":"https://github.com/giosh94mhz/symfony","homepage":"symfony.com","size":52470,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:2.3","ref":"2.3","sha":"b77d8c5bc59bdfc02d504eeb9c9bd3703c521b4d","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":458058,"name":"symfony","full_name":"symfony/symfony","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony","description":"The Symfony PHP framework","fork":false,"url":"https://api.github.com/repos/symfony/symfony","forks_url":"https://api.github.com/repos/symfony/symfony/forks","keys_url":"https://api.github.com/repos/symfony/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony/teams","hooks_url":"https://api.github.com/repos/symfony/symfony/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony/events","assignees_url":"https://api.github.com/repos/symfony/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony/tags","blobs_url":"https://api.github.com/repos/symfony/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony/subscription","commits_url":"https://api.github.com/repos/symfony/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/symfony/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony/merges","archive_url":"https://api.github.com/repos/symfony/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony/downloads","issues_url":"https://api.github.com/repos/symfony/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony/releases{/id}","created_at":"2010-01-04T14:21:21Z","updated_at":"2015-06-19T09:35:12Z","pushed_at":"2015-06-19T09:08:51Z","git_url":"git://github.com/symfony/symfony.git","ssh_url":"git@github.com:symfony/symfony.git","clone_url":"https://github.com/symfony/symfony.git","svn_url":"https://github.com/symfony/symfony","homepage":"symfony.com","size":1192911,"stargazers_count":10353,"watchers_count":10353,"language":"PHP","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4106,"mirror_url":null,"open_issues_count":834,"forks":4106,"open_issues":834,"watchers":10353,"default_branch":"2.8"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14372"},"html":{"href":"https://github.com/symfony/symfony/pull/14372"},"issue":{"href":"https://api.github.com/repos/symfony/symfony/issues/14372"},"comments":{"href":"https://api.github.com/repos/symfony/symfony/issues/14372/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14372/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14372/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony/statuses/cde2087fba166c00ef509b45bbe8a6fa767111f1"}}}}