为什么 Easyadmin 不考虑多对多关系中的约束



我有一个ManyToMany关系,如果我尝试从MySQL中删除一个相关项目,我会被错误阻止;相反,如果我尝试从Easyadmin中删除相同的项目,我不会被阻止。

我预期的行为也会被Easyadmin阻止(v. 1.16 with Symfony v. 3.3.10(。请帮忙...

这是我的 2 个实体:

铅:

[...]
/**
 * @ORMManyToMany(targetEntity="LeadInterest", inversedBy="leads")
 * @JoinTable(name="leads_interests",
 *     joinColumns={@ORMJoinColumn(name="lead_id", referencedColumnName="id")},
 *     inverseJoinColumns={@ORMJoinColumn(name="interest_id", referencedColumnName="id")}
 * )
 * @ORMOrderBy({"interestName": "ASC"})
 */
private $interests = null;
[...]
public function __construct() {
    $this->interests = new ArrayCollection();
}
public function addInterest(LeadInterest $i) 
{
    if(!$this->interests->contains($i)) {
        $this->interests->add($i);
    }
}
public function removeInterest(LeadInterest $i)
{
    $this->interests->removeElement($i);
}
public function getInterests()
{
    return $this->interests;
}
[...]

主要兴趣:

[...]
/**
 * @ORMManyToMany(targetEntity="Lead", mappedBy="interests")
 */
private $leads;
[...]
public function __construct() {
    $this->leads = new ArrayCollection();
    $this->lastUpdate = new DateTime();
}
public function addLead(Lead $lead)
{
    $this->leads[] = $lead;
    return $this;
}
public function removeLead(Lead $lead)
{
    $this->leads->removeElement($lead);
}
public function getLeads()
{
    return $this->leads;
}
[...]

这是我尝试从MySQL中删除une项目时的错误:

mysql> delete from leadInterest where id=6;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`app`.`leads_interests`, CONSTRAINT `FK_2135A27B5A95FF89` FOREIGN KEY (`interest_id`) REFERENCES `leadInterest` (`id`))
mysql> delete from lead where id=88;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`app`.`leads_interests`, CONSTRAINT `FK_2135A27B55458D` FOREIGN KEY (`lead_id`) REFERENCES `lead` (`id`))

谢谢

我不知道

为什么 EasyAdmin 没有抛出任何错误,但您显然没有告诉 MySQL 删除这些前置密钥onDelete="CASCADE"

/**
 * @ORMManyToMany(targetEntity="LeadInterest", inversedBy="leads")
 * @JoinTable(name="leads_interests",
 *     joinColumns={@ORMJoinColumn(name="lead_id", referencedColumnName="id", onDelete="CASCADE")},
 *     inverseJoinColumns={@ORMJoinColumn(name="interest_id", referencedColumnName="id", onDelete="CASCADE")}
 * )
 * @ORMOrderBy({"interestName": "ASC"})
 */

相关内容

  • 没有找到相关文章