whitebear
whitebear

Reputation: 12423

making unique Constraint on doctorine2

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

Answers (1)

1ed
1ed

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

Related Questions