In following example, I’d like the default value for $usergroup to be 1. Obviously, I cannot set it to 1 as it expects an Usergroup object.
/**
* @var integer $usergroup
*
* @ORM\ManyToOne(targetEntity="Usergroup")
*/
private $usergroup;
Is it possible to somehow set it to Usergroup object with id of 1 or should I handle it when I’m actually persisting the object?
You should have a service for creating new YourEntity instances. The service will know of to retrieve the default group, or how to create a reference to the default group, and will take care of passing it to the entity’s constructor.
For example: