Doctrine 2 not persisting the relation from owning side one to Many

Viewed 15161

I have this code

// ONE to many Bidir -- inverse side
    /**
     * @ORM\OneToMany(targetEntity="Item", mappedBy="Room", cascade={"persist"})
     **/
    protected $items;

The other side

// ONE to many Bidir-- own side
    /**
     * @ORM\ManyToOne(targetEntity="Room", inversedBy="items")
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
     **/
    protected $room;

My Problem is that i go to item page and i select Room , then i can see items preselecetd in Room page

But if i go to Room page and i try to multiselect many items , then those are not persisted

EDIT: I have seen that it is only happening for OneToMany relation ship. For Manyto Many they are working fine

EDIT2:

I am talking about the backend area where i have the form and select box where i can select multiple items. This form/CRUD code / controllers are genrated by doctrine. SO i don't need to add any extra function. Any way this is my controller code

$editForm   = $this->createForm(new RoomType(), $entity);


        $request = $this->getRequest();

        $editForm->bindRequest($request);
        if ($editForm->isValid()) {
            $em->persist($entity);
            $em->flush();

When i try to walk through in controller like this

foreach($entity->getItems() as $item)
        echo $item;

Then i can see all thye items there. So it means all items are there in main object but its not persisting them. i don't know why.

If there is owing , reverse side problem. How can i chnage the relationship from owing to inverse and inverse to owning

2 Answers
Related