{"action":"created","comment":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments/27554757","id":27554757,"diff_hunk":"@@ -0,0 +1,92 @@\n+<?php\n+\n+/*\n+ * This file is part of the FOSRestBundle package.\n+ *\n+ * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ */\n+\n+namespace FOS\\RestBundle\\Form\\Transformer;\n+\n+use Symfony\\Component\\Form\\DataTransformerInterface;\n+use Symfony\\Component\\Form\\Exception\\TransformationFailedException;\n+use Doctrine\\Common\\Persistence\\ObjectManager;\n+\n+/**\n+ * Class EntityToIdObjectTransformer\n+ *\n+ * @author Marc Juchli <mail@marcjuch.li>\n+ */\n+class EntityToIdObjectTransformer implements DataTransformerInterface {\n+\n+    /**\n+     * @var ObjectManager\n+     */\n+    private $om;\n+\n+    /**\n+     * @var String\n+     */\n+    private $entityName;\n+\n+    /**\n+     * @param ObjectManager $om\n+     * @param String $entityName\n+     */\n+    public function __construct(ObjectManager $om, $entityName)\n+    {\n+        $this->entityName = $entityName;\n+        $this->om = $om;\n+    }\n+\n+    /**\n+     * Do nothing.\n+     *\n+     * @param  Object|null $object\n+     * @return string\n+     */\n+    public function transform($object)\n+    {\n+        if (null === $object) {\n+            return \"\";\n+        }\n+\n+        return array_values($this->om->getClassMetadata($this->entityName)->getIdentifierValues($object))[0];","path":"Form/Transformer/EntityToIdObjectTransformer.php","position":57,"original_position":57,"commit_id":"12cbee07bc8aeb77ff5a39899a925b3c0ec8e773","original_commit_id":"12cbee07bc8aeb77ff5a39899a925b3c0ec8e773","user":{"login":"Baachi","id":833645,"avatar_url":"https://avatars.githubusercontent.com/u/833645?v=3","gravatar_id":"","url":"https://api.github.com/users/Baachi","html_url":"https://github.com/Baachi","followers_url":"https://api.github.com/users/Baachi/followers","following_url":"https://api.github.com/users/Baachi/following{/other_user}","gists_url":"https://api.github.com/users/Baachi/gists{/gist_id}","starred_url":"https://api.github.com/users/Baachi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Baachi/subscriptions","organizations_url":"https://api.github.com/users/Baachi/orgs","repos_url":"https://api.github.com/users/Baachi/repos","events_url":"https://api.github.com/users/Baachi/events{/privacy}","received_events_url":"https://api.github.com/users/Baachi/received_events","type":"User","site_admin":false},"body":"@lsmith77 I created a PR #1001 ","created_at":"2015-04-01T09:23:05Z","updated_at":"2015-04-01T09:23:05Z","html_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/987#discussion_r27554757","pull_request_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987","_links":{"self":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments/27554757"},"html":{"href":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/987#discussion_r27554757"},"pull_request":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987"}}},"pull_request":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987","id":30642322,"html_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/987","diff_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/987.diff","patch_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/987.patch","issue_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/987","number":987,"state":"closed","locked":false,"title":"DataTransformer to transform serialized objects containing an id to it's entity","user":{"login":"backender","id":955179,"avatar_url":"https://avatars.githubusercontent.com/u/955179?v=3","gravatar_id":"","url":"https://api.github.com/users/backender","html_url":"https://github.com/backender","followers_url":"https://api.github.com/users/backender/followers","following_url":"https://api.github.com/users/backender/following{/other_user}","gists_url":"https://api.github.com/users/backender/gists{/gist_id}","starred_url":"https://api.github.com/users/backender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/backender/subscriptions","organizations_url":"https://api.github.com/users/backender/orgs","repos_url":"https://api.github.com/users/backender/repos","events_url":"https://api.github.com/users/backender/events{/privacy}","received_events_url":"https://api.github.com/users/backender/received_events","type":"User","site_admin":false},"body":"According to the issue (https://github.com/FriendsOfSymfony/FOSRestBundle/issues/984) I created a transformer that can handle serialized objects containing an id and map it to the entity.\r\n\r\nThe use of this transfomer within a form type would look as follows:\r\n```php\r\n$transformer = new EntityToIdObjectTransformer($this->om, \"AcmeDemoBundle:MyEntity\");\r\n$builder->add($builder->create('myfield', 'text')->addModelTransformer($transformer))\r\n```\r\nThis way, the selialization process stays untouched.\r\n\r\nNot sure if this it's generic enough, otherwise it's documented here at least.","created_at":"2015-03-06T12:50:16Z","updated_at":"2015-04-01T09:23:05Z","closed_at":"2015-04-01T06:28:47Z","merged_at":"2015-04-01T06:28:47Z","merge_commit_sha":"d83ff6c3e7cc464ba0f8e413acb29afccb17bd5c","assignee":null,"milestone":{"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/milestones/4","html_url":"https://github.com/FriendsOfSymfony/FOSRestBundle/milestones/1.6.0","labels_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/milestones/4/labels","id":946879,"number":4,"title":"1.6.0","description":"","creator":{"login":"lsmith77","id":300279,"avatar_url":"https://avatars.githubusercontent.com/u/300279?v=3","gravatar_id":"","url":"https://api.github.com/users/lsmith77","html_url":"https://github.com/lsmith77","followers_url":"https://api.github.com/users/lsmith77/followers","following_url":"https://api.github.com/users/lsmith77/following{/other_user}","gists_url":"https://api.github.com/users/lsmith77/gists{/gist_id}","starred_url":"https://api.github.com/users/lsmith77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lsmith77/subscriptions","organizations_url":"https://api.github.com/users/lsmith77/orgs","repos_url":"https://api.github.com/users/lsmith77/repos","events_url":"https://api.github.com/users/lsmith77/events{/privacy}","received_events_url":"https://api.github.com/users/lsmith77/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":16,"state":"open","created_at":"2015-01-22T13:51:36Z","updated_at":"2015-04-01T06:29:57Z","due_on":"2015-03-30T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987/commits","review_comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987/comments","review_comment_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/987/comments","statuses_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/statuses/12cbee07bc8aeb77ff5a39899a925b3c0ec8e773","head":{"label":"backender:idobjecttransformer","ref":"idobjecttransformer","sha":"12cbee07bc8aeb77ff5a39899a925b3c0ec8e773","user":{"login":"backender","id":955179,"avatar_url":"https://avatars.githubusercontent.com/u/955179?v=3","gravatar_id":"","url":"https://api.github.com/users/backender","html_url":"https://github.com/backender","followers_url":"https://api.github.com/users/backender/followers","following_url":"https://api.github.com/users/backender/following{/other_user}","gists_url":"https://api.github.com/users/backender/gists{/gist_id}","starred_url":"https://api.github.com/users/backender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/backender/subscriptions","organizations_url":"https://api.github.com/users/backender/orgs","repos_url":"https://api.github.com/users/backender/repos","events_url":"https://api.github.com/users/backender/events{/privacy}","received_events_url":"https://api.github.com/users/backender/received_events","type":"User","site_admin":false},"repo":{"id":20098931,"name":"FOSRestBundle","full_name":"backender/FOSRestBundle","owner":{"login":"backender","id":955179,"avatar_url":"https://avatars.githubusercontent.com/u/955179?v=3","gravatar_id":"","url":"https://api.github.com/users/backender","html_url":"https://github.com/backender","followers_url":"https://api.github.com/users/backender/followers","following_url":"https://api.github.com/users/backender/following{/other_user}","gists_url":"https://api.github.com/users/backender/gists{/gist_id}","starred_url":"https://api.github.com/users/backender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/backender/subscriptions","organizations_url":"https://api.github.com/users/backender/orgs","repos_url":"https://api.github.com/users/backender/repos","events_url":"https://api.github.com/users/backender/events{/privacy}","received_events_url":"https://api.github.com/users/backender/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/backender/FOSRestBundle","description":"This Bundle provides various tools to rapidly develop RESTful API's with Symfony2","fork":true,"url":"https://api.github.com/repos/backender/FOSRestBundle","forks_url":"https://api.github.com/repos/backender/FOSRestBundle/forks","keys_url":"https://api.github.com/repos/backender/FOSRestBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/backender/FOSRestBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/backender/FOSRestBundle/teams","hooks_url":"https://api.github.com/repos/backender/FOSRestBundle/hooks","issue_events_url":"https://api.github.com/repos/backender/FOSRestBundle/issues/events{/number}","events_url":"https://api.github.com/repos/backender/FOSRestBundle/events","assignees_url":"https://api.github.com/repos/backender/FOSRestBundle/assignees{/user}","branches_url":"https://api.github.com/repos/backender/FOSRestBundle/branches{/branch}","tags_url":"https://api.github.com/repos/backender/FOSRestBundle/tags","blobs_url":"https://api.github.com/repos/backender/FOSRestBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/backender/FOSRestBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/backender/FOSRestBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/backender/FOSRestBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/backender/FOSRestBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/backender/FOSRestBundle/languages","stargazers_url":"https://api.github.com/repos/backender/FOSRestBundle/stargazers","contributors_url":"https://api.github.com/repos/backender/FOSRestBundle/contributors","subscribers_url":"https://api.github.com/repos/backender/FOSRestBundle/subscribers","subscription_url":"https://api.github.com/repos/backender/FOSRestBundle/subscription","commits_url":"https://api.github.com/repos/backender/FOSRestBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/backender/FOSRestBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/backender/FOSRestBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/backender/FOSRestBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/backender/FOSRestBundle/contents/{+path}","compare_url":"https://api.github.com/repos/backender/FOSRestBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/backender/FOSRestBundle/merges","archive_url":"https://api.github.com/repos/backender/FOSRestBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/backender/FOSRestBundle/downloads","issues_url":"https://api.github.com/repos/backender/FOSRestBundle/issues{/number}","pulls_url":"https://api.github.com/repos/backender/FOSRestBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/backender/FOSRestBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/backender/FOSRestBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/backender/FOSRestBundle/labels{/name}","releases_url":"https://api.github.com/repos/backender/FOSRestBundle/releases{/id}","created_at":"2014-05-23T12:37:07Z","updated_at":"2014-06-02T14:14:10Z","pushed_at":"2015-03-29T23:38:26Z","git_url":"git://github.com/backender/FOSRestBundle.git","ssh_url":"git@github.com:backender/FOSRestBundle.git","clone_url":"https://github.com/backender/FOSRestBundle.git","svn_url":"https://github.com/backender/FOSRestBundle","homepage":"http://friendsofsymfony.github.com/","size":2867,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"FriendsOfSymfony:master","ref":"master","sha":"558c173ac28164aebc4482d3f90773a9aa7b4206","user":{"login":"FriendsOfSymfony","id":529709,"avatar_url":"https://avatars.githubusercontent.com/u/529709?v=3","gravatar_id":"","url":"https://api.github.com/users/FriendsOfSymfony","html_url":"https://github.com/FriendsOfSymfony","followers_url":"https://api.github.com/users/FriendsOfSymfony/followers","following_url":"https://api.github.com/users/FriendsOfSymfony/following{/other_user}","gists_url":"https://api.github.com/users/FriendsOfSymfony/gists{/gist_id}","starred_url":"https://api.github.com/users/FriendsOfSymfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FriendsOfSymfony/subscriptions","organizations_url":"https://api.github.com/users/FriendsOfSymfony/orgs","repos_url":"https://api.github.com/users/FriendsOfSymfony/repos","events_url":"https://api.github.com/users/FriendsOfSymfony/events{/privacy}","received_events_url":"https://api.github.com/users/FriendsOfSymfony/received_events","type":"Organization","site_admin":false},"repo":{"id":1509011,"name":"FOSRestBundle","full_name":"FriendsOfSymfony/FOSRestBundle","owner":{"login":"FriendsOfSymfony","id":529709,"avatar_url":"https://avatars.githubusercontent.com/u/529709?v=3","gravatar_id":"","url":"https://api.github.com/users/FriendsOfSymfony","html_url":"https://github.com/FriendsOfSymfony","followers_url":"https://api.github.com/users/FriendsOfSymfony/followers","following_url":"https://api.github.com/users/FriendsOfSymfony/following{/other_user}","gists_url":"https://api.github.com/users/FriendsOfSymfony/gists{/gist_id}","starred_url":"https://api.github.com/users/FriendsOfSymfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FriendsOfSymfony/subscriptions","organizations_url":"https://api.github.com/users/FriendsOfSymfony/orgs","repos_url":"https://api.github.com/users/FriendsOfSymfony/repos","events_url":"https://api.github.com/users/FriendsOfSymfony/events{/privacy}","received_events_url":"https://api.github.com/users/FriendsOfSymfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FriendsOfSymfony/FOSRestBundle","description":"This Bundle provides various tools to rapidly develop RESTful API's with Symfony2","fork":false,"url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle","forks_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/forks","keys_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/teams","hooks_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/hooks","issue_events_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/events{/number}","events_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/events","assignees_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/assignees{/user}","branches_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/branches{/branch}","tags_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/tags","blobs_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/languages","stargazers_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/stargazers","contributors_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/contributors","subscribers_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/subscribers","subscription_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/subscription","commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/contents/{+path}","compare_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/merges","archive_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/downloads","issues_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues{/number}","pulls_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/labels{/name}","releases_url":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/releases{/id}","created_at":"2011-03-21T23:14:13Z","updated_at":"2015-04-01T06:28:49Z","pushed_at":"2015-04-01T09:22:16Z","git_url":"git://github.com/FriendsOfSymfony/FOSRestBundle.git","ssh_url":"git@github.com:FriendsOfSymfony/FOSRestBundle.git","clone_url":"https://github.com/FriendsOfSymfony/FOSRestBundle.git","svn_url":"https://github.com/FriendsOfSymfony/FOSRestBundle","homepage":"http://friendsofsymfony.github.com/","size":6524,"stargazers_count":1102,"watchers_count":1102,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":443,"mirror_url":null,"open_issues_count":79,"forks":443,"open_issues":79,"watchers":1102,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987"},"html":{"href":"https://github.com/FriendsOfSymfony/FOSRestBundle/pull/987"},"issue":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/987"},"comments":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/issues/987/comments"},"review_comments":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987/comments"},"review_comment":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/pulls/987/commits"},"statuses":{"href":"https://api.github.com/repos/FriendsOfSymfony/FOSRestBundle/statuses/12cbee07bc8aeb77ff5a39899a925b3c0ec8e773"}}}}