{"action":"created","issue":{"url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/issues/431","labels_url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/issues/431/labels{/name}","comments_url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/issues/431/comments","events_url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/issues/431/events","html_url":"https://github.com/sensiolabs/SensioGeneratorBundle/pull/431","id":119015859,"number":431,"title":"Fix form generation for entities with ManyToOne relations","user":{"login":"Maff-","id":371966,"avatar_url":"https://avatars.githubusercontent.com/u/371966?v=3","gravatar_id":"","url":"https://api.github.com/users/Maff-","html_url":"https://github.com/Maff-","followers_url":"https://api.github.com/users/Maff-/followers","following_url":"https://api.github.com/users/Maff-/following{/other_user}","gists_url":"https://api.github.com/users/Maff-/gists{/gist_id}","starred_url":"https://api.github.com/users/Maff-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Maff-/subscriptions","organizations_url":"https://api.github.com/users/Maff-/orgs","repos_url":"https://api.github.com/users/Maff-/repos","events_url":"https://api.github.com/users/Maff-/events{/privacy}","received_events_url":"https://api.github.com/users/Maff-/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/labels/FINISHED","name":"FINISHED","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-26T10:35:59Z","updated_at":"2015-12-14T18:37:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/pulls/431","html_url":"https://github.com/sensiolabs/SensioGeneratorBundle/pull/431","diff_url":"https://github.com/sensiolabs/SensioGeneratorBundle/pull/431.diff","patch_url":"https://github.com/sensiolabs/SensioGeneratorBundle/pull/431.patch"},"body":"When trying to generate a Form Type for an Entity that has a `@ORM\\ManyToOne` relation, a `Twig_Error_Runtime` is thrown:\r\n\r\n> [Twig_Error_Runtime]\r\n> Key \"author\" for array with keys \"id, title\" does not exist in \"form/FormType.php.twig\" at line 29\r\n\r\nThis happens because the associated field is returned by `DoctrineFormGenerator::getFieldsFromMetadata()`, but does not exists in `ClassMetadataInfo::$fieldMappings`.\r\n\r\nThis problem occurred in a project created with the Symfony installer (based on v2.8.0-BETA1) and can be reproduced with the entities below.\r\n\r\nThis pull request fixes the problem.\r\n\r\n---\r\n\r\nComposer package versions in project:\r\n```\r\ndoctrine/annotations                 v1.2.7\r\ndoctrine/cache                       v1.5.1\r\ndoctrine/collections                 v1.3.0\r\ndoctrine/common                      v2.5.1\r\ndoctrine/dbal                        v2.5.2\r\ndoctrine/doctrine-bundle             1.6.0\r\ndoctrine/doctrine-cache-bundle       1.2.1\r\ndoctrine/inflector                   v1.1.0\r\ndoctrine/instantiator                1.0.5\r\ndoctrine/lexer                       v1.0.1\r\ndoctrine/orm                         v2.5.1\r\nincenteev/composer-parameter-handler v2.1.2\r\nircmaxell/password-compat            v1.0.4\r\njdorn/sql-formatter                  v1.2.17\r\nmonolog/monolog                      1.17.2\r\nparagonie/random_compat              1.1.0\r\npsr/log                              1.0.0\r\nsensio/distribution-bundle           dev-master 1045b31\r\nsensio/framework-extra-bundle        v3.0.11\r\nsensio/generator-bundle              v3.0.0\r\nsensiolabs/security-checker          v3.0.2\r\nswiftmailer/swiftmailer              v5.4.1\r\nsymfony/monolog-bundle               2.8.1\r\nsymfony/phpunit-bridge               v2.7.6\r\nsymfony/polyfill-intl-icu            v1.0.0\r\nsymfony/polyfill-mbstring            v1.0.0\r\nsymfony/polyfill-php54               v1.0.0\r\nsymfony/polyfill-php55               v1.0.0\r\nsymfony/polyfill-php56               v1.0.0\r\nsymfony/polyfill-php70               v1.0.0\r\nsymfony/polyfill-util                v1.0.0\r\nsymfony/security-acl                 v2.7.6\r\nsymfony/swiftmailer-bundle           v2.3.8\r\nsymfony/symfony                      2.8.x-dev 3b99b3a\r\ntwig/twig                            v1.23.1\r\n```\r\n\r\n```php\r\n<?php\r\n\r\nnamespace AppBundle\\Entity;\r\n\r\nuse Doctrine\\ORM\\Mapping as ORM;\r\n\r\n/**\r\n * Book\r\n *\r\n * @ORM\\Table(name=\"book\")\r\n * @ORM\\Entity(repositoryClass=\"AppBundle\\Repository\\BookRepository\")\r\n */\r\nclass Book\r\n{\r\n    /**\r\n     * @var int\r\n     *\r\n     * @ORM\\Column(name=\"id\", type=\"integer\")\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\r\n     */\r\n    private $id;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"title\", type=\"string\", length=255, unique=true)\r\n     */\r\n    private $title;\r\n\r\n    /**\r\n     * @var Author\r\n     *\r\n     * @ORM\\JoinColumn(name=\"author_id\", referencedColumnName=\"id\")\r\n     * @ORM\\ManyToOne(targetEntity=\"AppBundle\\Entity\\Author\")\r\n     */\r\n    private $author;\r\n\r\n    // getters and setters left out for conciseness\r\n}\r\n```\r\n```php\r\n<?php\r\n\r\nnamespace AppBundle\\Entity;\r\n\r\nuse Doctrine\\ORM\\Mapping as ORM;\r\n\r\n/**\r\n * Author\r\n *\r\n * @ORM\\Table(name=\"author\")\r\n * @ORM\\Entity(repositoryClass=\"AppBundle\\Repository\\AuthorRepository\")\r\n */\r\nclass Author\r\n{\r\n    /**\r\n     * @var int\r\n     *\r\n     * @ORM\\Column(name=\"id\", type=\"integer\")\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\r\n     */\r\n    private $id;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"name\", type=\"string\", length=255)\r\n     */\r\n    private $name;\r\n\r\n    // getters and setters left out for conciseness\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/issues/comments/164520507","html_url":"https://github.com/sensiolabs/SensioGeneratorBundle/pull/431#issuecomment-164520507","issue_url":"https://api.github.com/repos/sensiolabs/SensioGeneratorBundle/issues/431","id":164520507,"user":{"login":"afurculita","id":3129631,"avatar_url":"https://avatars.githubusercontent.com/u/3129631?v=3","gravatar_id":"","url":"https://api.github.com/users/afurculita","html_url":"https://github.com/afurculita","followers_url":"https://api.github.com/users/afurculita/followers","following_url":"https://api.github.com/users/afurculita/following{/other_user}","gists_url":"https://api.github.com/users/afurculita/gists{/gist_id}","starred_url":"https://api.github.com/users/afurculita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afurculita/subscriptions","organizations_url":"https://api.github.com/users/afurculita/orgs","repos_url":"https://api.github.com/users/afurculita/repos","events_url":"https://api.github.com/users/afurculita/events{/privacy}","received_events_url":"https://api.github.com/users/afurculita/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T18:37:04Z","updated_at":"2015-12-14T18:37:04Z","body":":+1:"}}