I'm building an API on Symfony2 an I have a Model ItemOrder with a ManyToOne relationship to a Model Item. I have a few Items in my database, and I want to add an ItemOrder that points to an Item that is already in the database, and whose id I know. So my first approach is this:
$item = new Item();
$item->setId(2);
$orderItem = new OrderItem();
$orderItem->setItem($item);
$em->persist($orderItem);
$em->flush();
However, Symfony2 understand that I'm trying to create a new item. I know that a valid approach would be fetching the Item object with the entity manager, and then assign it to the ItemOrder, but I think it's a not very efficient way of doing it.
So how should this be done?