dongzhang3482 2019-04-23 06:58
浏览 47
已采纳

如何使用Doctrine在Symfony 4中组合两个独特的列?

I have a table named 'student_assignment' in which I have multiple columns from which I am showing 2 of them below:

Both of these columns are also foreign keys.

StudentId   assignmentId
    10           7           -> allowed
    10           8           -> allowed
    11           7           -> allowed
    11           7           -> not allowed, the combination of 11 7 already exists in table

I have tried this in my entity file, but it does not work.

/**
 * Webkul\CampusConnect\Entity\StudentAssignment
 *
 * @Table(name="student_assignment", 
 *    uniqueConstraints={
 *        @UniqueConstraint(name="assignment_unique", 
 *            columns={"student", "assignment"})
 *    }
 * )
 * @Entity
 */

Please how to implement this using ORM in symfony 4.

I have a link which does ther same but in Mysql. I want the solution for Symfony ORM. enter link description here

Error:

[Semantical Error] The annotation "@Table" in class Webkul\CampusConnect\En tity\StudentAssignment was never imported. Did you maybe forget to add a "u se" statement for this annotation?

Entity:

namespace Webkul\CampusConnect\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Table;

/**
 * Webkul\CampusConnect\Entity\StudentAssignment
 *
 * @ORM\Table(name="student_assignment", 
 *    uniqueConstraints={
 *        @UniqueConstraint(name="assignment_unique", 
 *            columns={"student", "assignment"})
 *    }
 * )
 * @Entity
 */
class StudentAssignment
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Webkul\CampusConnect\Entity\Student", inversedBy="studentAssignments")
     * @ORM\JoinColumn(onDelete="CASCADE")
     */
    private $student;
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 VBA中使用FindWindowEx函数如何向网页表单中的多个文本框中的某一个文本框发送消息
      • ¥15 关于#glmb#的问题,如何解决?
      • ¥15 TI的TMS320F28335,RS485串口进行SCI-B通信出错
      • ¥15 XML文件报错不允许出现此特性,百度也搜不到解决方法
      • ¥15 FTPC共同交流学习
      • ¥15 关于#python##pyqt#的问题,如何解决?
      • ¥15 html+css网页设计 html+css网页设计
      • ¥15 用html加css制作一个网页
      • ¥200 MFC中如何对ListCtrl的某一列的文本能换行显示
      • ¥15 clion添加库文件