{"action":"created","issue":{"url":"https://api.github.com/repos/sonata-project/SonataMediaBundle/issues/610","repository_url":"https://api.github.com/repos/sonata-project/SonataMediaBundle","labels_url":"https://api.github.com/repos/sonata-project/SonataMediaBundle/issues/610/labels{/name}","comments_url":"https://api.github.com/repos/sonata-project/SonataMediaBundle/issues/610/comments","events_url":"https://api.github.com/repos/sonata-project/SonataMediaBundle/issues/610/events","html_url":"https://github.com/sonata-project/SonataMediaBundle/issues/610","id":39898120,"number":610,"title":"user uploading picture","user":{"login":"anooxy","id":654413,"avatar_url":"https://avatars.githubusercontent.com/u/654413?v=3","gravatar_id":"","url":"https://api.github.com/users/anooxy","html_url":"https://github.com/anooxy","followers_url":"https://api.github.com/users/anooxy/followers","following_url":"https://api.github.com/users/anooxy/following{/other_user}","gists_url":"https://api.github.com/users/anooxy/gists{/gist_id}","starred_url":"https://api.github.com/users/anooxy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anooxy/subscriptions","organizations_url":"https://api.github.com/users/anooxy/orgs","repos_url":"https://api.github.com/users/anooxy/repos","events_url":"https://api.github.com/users/anooxy/events{/privacy}","received_events_url":"https://api.github.com/users/anooxy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2014-08-10T00:50:00Z","updated_at":"2016-07-27T10:22:38Z","closed_at":"2016-04-21T12:35:33Z","body":"I'm trying to create a form the user can use to add a profile picture:\r\n\r\n    $user = $this->getUser();\r\n        \r\n        $builder = $this->createFormBuilder($user);\r\n        $builder->add('media', 'sonata_media_type', array(\r\n            'provider' => 'sonata.media.provider.image',\r\n            'context' => 'user_picture',\r\n        ))\r\n        ->add('Upload', 'submit');\r\n\r\n        $form = $builder->getForm();\r\n\r\n        if($request->getMethod() == 'POST')\r\n        {\r\n            $form->handleRequest($request);\r\n\r\n            $media = $form->getData();\r\n\r\n            $user = $this->getUser();\r\n            $media['media']->setTutor($user);\r\n\r\n            $em = $this->getDoctrine()->getManager();\r\n            $em->persist($media['media']);\r\n            $em->flush();\r\n        }\r\n\r\n        return $this->render('SkooliUserBundle:Media:index.html.twig', array(\r\n            'form' => $form->createView()\r\n        ));\r\n\r\nThat code is giving me the following error:\r\n\r\n    The form's view data is expected to be an instance of class Application\\Sonata\\MediaBundle\\Entity\\Media, but is an instance of class Doctrine\\ORM\\PersistentCollection. You can avoid this error by setting the \"data_class\" option to null or by adding a view transformer that transforms an instance of class Doctrine\\ORM\\PersistentCollection to an instance of Application\\Sonata\\MediaBundle\\Entity\\Media.\r\n\r\nMy relationship needs to be one-to-many, a single user needs to have several user pictures and or other documents. On Media.orm.xml I got this:\r\n\r\n        <many-to-one field=\"user\"\r\n                     target-entity=\"\\XXX\\Bundle\\UserBundle\\Entity\\User\"\r\n                     inversed-by=\"media\">\r\n            <join-column\r\n                    name=\"user_id\"\r\n                    referenced-column-name=\"id\"\r\n                    />\r\n        </many-to-one>\r\n\r\nAnd on my User.orm.yml:\r\n\r\n    media:\r\n            targetEntity: Application\\Sonata\\MediaBundle\\Entity\\Media\r\n            mappedBy: user\r\n            cascade: [\"persist\"]\r\n\r\nI don't understand what is the problem."},"comment":{"url":"https://api.github.com/repos/sonata-project/SonataMediaBundle/issues/comments/235546740","html_url":"https://github.com/sonata-project/SonataMediaBundle/issues/610#issuecomment-235546740","issue_url":"https://api.github.com/repos/sonata-project/SonataMediaBundle/issues/610","id":235546740,"user":{"login":"zneel","id":14263028,"avatar_url":"https://avatars.githubusercontent.com/u/14263028?v=3","gravatar_id":"","url":"https://api.github.com/users/zneel","html_url":"https://github.com/zneel","followers_url":"https://api.github.com/users/zneel/followers","following_url":"https://api.github.com/users/zneel/following{/other_user}","gists_url":"https://api.github.com/users/zneel/gists{/gist_id}","starred_url":"https://api.github.com/users/zneel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zneel/subscriptions","organizations_url":"https://api.github.com/users/zneel/orgs","repos_url":"https://api.github.com/users/zneel/repos","events_url":"https://api.github.com/users/zneel/events{/privacy}","received_events_url":"https://api.github.com/users/zneel/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T10:22:38Z","updated_at":"2016-07-27T10:22:38Z","body":"Hi @anooxy did you solve it? I have exactly the same issue"}}
{"actor":{"display_login":"zneel"}}