Reputation: 12423
I would like to make uniqueConstraint user and lesson.
/**
* @ORM\Table(name="ReviewSchool",uniqueConstraints={
* @ORM\UniqueConstraint(name="lessonid", columns={"lesson", "user"})})
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class ReviewSchool
{
* @ORM\ManyToOne(targetEntity="Lesson",inversedBy="reviewschool")
* @ORM\JoinColumn(name="review_lesson", referencedColumnName="id",onDelete="cascade")
*/
private $lesson;
/**
*
* @ORM\ManyToOne(targetEntity="User",inversedBy="reviewschool")
* @ORM\JoinColumn(name="review_user",referencedColumnName="id",onDelete="cascade")
*/
private $user;
However it shows
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'lesson' on table 'ReviewSchool'.
Surely I have 'lesson' column, how can I solve this? I have misunderstood something??
Upvotes: 1
Views: 50
Reputation: 3668
It allows to hint the SchemaTool to generate a database unique constraint on the specified table columns. It only has meaning in the SchemaTool schema generation context.
So you have to use column names. In your case:
@ORM\UniqueConstraint(columns={"review_lesson", "review_user"})}
Upvotes: 1