Answer the question
In order to leave comments, you need to log in
Why doesn't Doctrine record the parameter passed to it?
Class Employees
{
/**
* Parent UID
* @var int
*
* @ORM\Column(name="parentId", type="integer", nullable=true)
*/
private $parentId;
/**
* Division ID
* @var int
*
* @ORM\Column(name="divisionId", type="integer", nullable=true)
*/
private $divisionId = "";
/**
* Подразделение сотрудника
* @ORM\OneToOne(targetEntity="Statistic\Entity\Division")
* @ORM\JoinColumn(name="divisionId", referencedColumnName="id")
*/
private $division;
/**
* Руководитель сотрудника
* @ORM\OneToOne(targetEntity="Employees\Entity\Employees")
* @ORM\JoinColumn(name="parentId", referencedColumnName="id")
*/
private $parent;
}
...
$employee->setParentId(4);
$entityManager->persist($employee);
$entityManager->flush();
Answer the question
In order to leave comments, you need to log in
Remove the parentId field, and everything will work. Such a field in the database will make the doctrine itself, when creating a relationship between tables. You can leave this field in the entity if you so desire, but you still need to establish an association between records with the parent field.
Plus, it looks like you have an error in the relationship type in the parent and division fields. You have a OneToOne relationship type, that is, a manager can have only one employee, and a department can have only one employee. Set the connection type to ManyToOne (see the article ).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question