구체적으로 말씀 드리겠습니다. 엔티티 퀘스트, 도시 및 조직자가 있습니다. 나 주최자 제거하려고하면 즉 갖는다 퀘스트 에러 관계는 'WHERE ID =? 주최자 삭제'symfony (교리)에서 엔티티의 관계에 대한 컨설팅
예외가 실행하는 동안 발생 나타나는 와 PARAMS [522] :
SQLSTATE [23000] : 무결성 제약 조건 위반 : 1451 삭제할 수 없습니다 또는 업데이트는 부모 행 :. 외래 키 제약 조건이 (실패
test
Quest
, CONSTRAINTFK_82D6D713876C4DDA
FOREIGN KEY (organizer_id
) 참조Organizer
(id
))
나는 관계를 구성하는 올바른 방법과 절대 혼동합니다. 로직은 다음과 같습니다.
- 새로운 도시를 추가합니다.
- 새로운 주최자를 추가하고 주최자에게 도시를 추가합니다.
- 새로운 퀘스트를 만들고 도시와 조직도를 넣는 것보다.
- 주최자를 제거하면 주최자 id는 퀘스트에서 (퀘스트를 제거해서는 안됨)을 제거해야합니다.
- 도시에서 주최자 ID를 제거해야하는 경우 도 제거해야합니다 (도시를 삭제하면 안됨).
매우 멍청한 설명을 드려 죄송합니다.하지만 오해를 배제하려고합니다.
음, 상황에 맞는 엔티티 관계를 사용해야합니까?
class Quest {
...
/**
* @ORM\JoinColumn(name="organizer_id", referencedColumnName="id")
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Organizer")
*/
protected $organizer;
}
class Organizer {
...
/**
* @ORM\Column(type="string", length=140)
*/
protected $name;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\City", inversedBy="organizers")
* @ORM\JoinTable(name="organizers_cities")
*/
protected $cities;
public function __construct() {
$this->quests = new ArrayCollection(); // i don't remember why this is here
}
}
class City {
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Organizer", mappedBy="cities")
*/
protected $organizers;
/**
* Constructor
*/
public function __construct() {
$this->quests = new \Doctrine\Common\Collections\ArrayCollection();
$this->organizers = new \Doctrine\Common\Collections\ArrayCollection();
}
}
그는 캐스케이드에서 퀘스트를 제거하고 싶지 않으며 관계 만 null로 만듭니다. 코드가 수행하는 작업인지 확인하십시오. – abdiel
아, 이해가 안됐다. 나는 대답을 다시 썼다. 감사. – Alsatian