I have the entity (such as below). I want to set some default values while creating.
As you can see in __construct
, it is easy to set the $name
(string), but how can I set the $group
? (for example I know that there is a group in database with id=122
)
/**
* @ORM\Entity
*/
class Person {
private $id;
/** @ORM\Column(type="string") */
private $name;
/**
* @ORM\ManyToOne(targetEntity="Group", inversedBy="persons")
* @ORM\JoinColumn(referencedColumnName="id")
*/
private $group;
public function setGroup(Group $group)
{
$this->group = $group;
$group->addPerson($this);
}
// ... setters/getters
//construct default Person
public function __construct()
{
$this->setName("Mike");
$this->setGroup($EXISTING_GROUP_FROM_MY_DB); // <<--------------
}
}