Должно быть так:
- Пользователь-> Отчеты OneToMany
- Задача-> Отчеты OneToMany
- Отчет-> Пользователь ManyToOne
- Report-> Task ManyToOne
- UniqueConstraint в отчете с полями id, user, task *
Для отношений: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#one -в-многих-двунаправленных
Для UniqueConstraint: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/annotations-reference.html#uniqueconstraint
Я не проверял код ...
/**
* @Doctrine\ORM\Mapping\Entity()
* @Doctrine\ORM\Mapping\Table(name="user")
*/
class User
{
/**
* @Doctrine\ORM\Mapping\Id
* @Doctrine\ORM\Mapping\Column(type="integer")
* @Doctrine\ORM\Mapping\GeneratedValue
*/
protected $id;
/**
* @Doctrine\ORM\Mapping\Column(type="text")
*/
protected $name;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="Report", mappedBy="user")
*/
protected $reports;
public function __construct() {
$this->reports = new \Doctrine\Common\Collections\ArrayCollection();
}
// addReport, removeReport, Getters and setters
}
/**
* @Doctrine\ORM\Mapping\Entity()
* @Doctrine\ORM\Mapping\Table(name="task")
*/
class Task
{
/**
* @Doctrine\ORM\Mapping\Id
* @Doctrine\ORM\Mapping\Column(type="integer")
* @Doctrine\ORM\Mapping\GeneratedValue
*/
protected $id;
/**
* @Doctrine\ORM\Mapping\Column(type="text")
*/
protected $name;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="Report", mappedBy="task")
*/
protected $reports;
public function __construct() {
$this->reports = new \Doctrine\Common\Collections\ArrayCollection();
}
// addReport, removeReport, Getters and setters
}
/**
* @Doctrine\ORM\Mapping\Entity()
* @Doctrine\ORM\Mapping\Table(name="report",uniqueConstraints={
* @Doctrine\ORM\Mapping\UniqueConstraint(name="report_user_task_idx", columns={"id", "user", "task"})
* })
*/
class Report
{
/**
* @Doctrine\ORM\Mapping\Id
* @Doctrine\ORM\Mapping\Column(type="integer")
* @Doctrine\ORM\Mapping\GeneratedValue
*/
protected $id;
/**
* @Doctrine\ORM\Mapping\Column(type="text")
*/
protected $comment;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="reports")
*/
protected $user;
/**
* @ORM\ManyToOne(targetEntity="Task", inversedBy="reports")
*/
protected $task;
// Getters and setters
}