{"action":"created","issue":{"url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/1295","repository_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle","labels_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/1295/labels{/name}","comments_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/1295/comments","events_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/1295/events","html_url":"https://github.com/sonata-project/SonataAdminBundle/issues/1295","id":13337087,"number":1295,"title":"Inverse \"Many\" Side in Embedded sonata_type_collection one-to-many Form Not Disassociating When \"Delete\" Checked","user":{"login":"grichards","id":454158,"avatar_url":"https://avatars.githubusercontent.com/u/454158?v=3","gravatar_id":"","url":"https://api.github.com/users/grichards","html_url":"https://github.com/grichards","followers_url":"https://api.github.com/users/grichards/followers","following_url":"https://api.github.com/users/grichards/following{/other_user}","gists_url":"https://api.github.com/users/grichards/gists{/gist_id}","starred_url":"https://api.github.com/users/grichards/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grichards/subscriptions","organizations_url":"https://api.github.com/users/grichards/orgs","repos_url":"https://api.github.com/users/grichards/repos","events_url":"https://api.github.com/users/grichards/events{/privacy}","received_events_url":"https://api.github.com/users/grichards/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2013-04-18T07:26:42Z","updated_at":"2016-02-12T11:53:08Z","closed_at":"2016-02-12T11:53:08Z","body":"I've seen similar reports, but no clear solution. I've followed the pattern given in SonataMediaBundle, but to no avail in this use case. Here is sample code:\r\n\r\n```php\r\nclass Company {\r\n    /**\r\n     * @var Collection\r\n     *\r\n     * @ORM\\OneToMany(targetEntity=\"My\\Bundle\\Entity\\User\\Controller\", mappedBy=\"company\", cascade={\"persist\", \"remove\"})\r\n     * @ORM\\JoinColumn(name=\"controller_id\", referencedColumnName=\"id\")\r\n     */\r\n    private $controllers;\r\n\r\n    public function setControllers($controllers)\r\n    {\r\n        $this->controllers = new ArrayCollection();\r\n\r\n        if (count($controllers)) {\r\n            foreach ($controllers as $controller) {\r\n                $controller->setCompany($this);\r\n                $this->addController($controller);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nclass Controller {\r\n    /**\r\n     *\r\n     * @var Company\r\n     *\r\n     *\r\n     * @ORM\\ManyToOne(targetEntity=\"My\\Bundle\\Entity\\Company\", inversedBy=\"controllers\", cascade={\"persist\", \"remove\"})\r\n     * @Assert\\Type(type=\"TCS\\TimecardBundle\\Entity\\Company\")\r\n     */\r\n    private $company;\r\n}\r\n\r\nclass CompanyAdmin {\r\n\r\n    protected function configureFormFields(FormMapper $formMapper)\r\n    {\r\n\r\n        $formMapper\r\n            ->with('Controllers')\r\n                ->add('controllers', 'sonata_type_collection', array('label' => false, 'required' => false, 'by_reference' => false), array('edit' => 'inline', 'inline' => 'table'))\r\n            ->end();\r\n    }\r\n\r\n    public function prePersist($company)\r\n    {\r\n        $company->setControllers($company->getControllers());\r\n    }\r\n\r\n    public function preUpdate($company)\r\n    {\r\n        $company->setControllers($company->getControllers());\r\n    }\r\n\r\n}\r\n```\r\n\r\nSo that's the setup, pretty much taken right out of examples I've seen posted here, on StackOverflow, and in SonataMediaBundle.\r\n\r\nMy expectation is that when I check \"delete\" on a few \"Controllers\" in the embedded forms and then save the \"Company\" form... the selected Controllers will be disassociated with the Company (i.e. the company_id on the Controller objects will be set to null). I do NOT want the Controllers to be \"deleted\" just the relationship to be removed.\r\n\r\nHowever, that is not the case... am I misunderstanding something or is this a real problem?\r\n\r\nOne possibly important thing I've noticed is that the the preUpdate and prePersist methods are ONLY retrieving the non-deleted controllers when I call $company->getControllers() and pass that to $company->setControllers()... but it just seems that Doctrine doesn't notice the missing Controllers need to be disassociated.\r\n\r\nTY for any help."},"comment":{"url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/comments/183293618","html_url":"https://github.com/sonata-project/SonataAdminBundle/issues/1295#issuecomment-183293618","issue_url":"https://api.github.com/repos/sonata-project/SonataAdminBundle/issues/1295","id":183293618,"user":{"login":"core23","id":3440437,"avatar_url":"https://avatars.githubusercontent.com/u/3440437?v=3","gravatar_id":"","url":"https://api.github.com/users/core23","html_url":"https://github.com/core23","followers_url":"https://api.github.com/users/core23/followers","following_url":"https://api.github.com/users/core23/following{/other_user}","gists_url":"https://api.github.com/users/core23/gists{/gist_id}","starred_url":"https://api.github.com/users/core23/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/core23/subscriptions","organizations_url":"https://api.github.com/users/core23/orgs","repos_url":"https://api.github.com/users/core23/repos","events_url":"https://api.github.com/users/core23/events{/privacy}","received_events_url":"https://api.github.com/users/core23/received_events","type":"User","site_admin":false},"created_at":"2016-02-12T11:53:08Z","updated_at":"2016-02-12T11:53:08Z","body":"If this is an active issue, please reopen @grichards "}}