Q: symfony2 setter for related entity id My relation in entity:
 /**
 * @ORM\ManyToOne(targetEntity="Group")
 */
protected $group;

now I have a setter method setGroup() to set related entity, but there seems no method setGroupId() to set group_id without the entity object. How can I set group_id directly?

A: I suggest you have a look at Doctrine EntityManager ->getReference() method.
$user->setGroup($em->getReference('Group', 10));


A: Use a custom repository to create a specific method that will fetch the group, and then set it with setGroup. 
Edit: You can even directly add/update the id via a SQL query: https://stackoverflow.com/a/10215061
But that's dirty. 

A: Try defining another field (groupId) and map it directly ot your field in the database.
