多対多の関係に重大な問題があります。私のシナリオでは、 aは多くのとCandidate
接続でき、多くのを持つ可能性があります。Projects
Project
Candidates
CREATE TABLE `CANDIDATE` (
`ID` INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`ID`) )ENGINE = InnoDB;
CREATE `PROJECT` (
`ID` INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`ID`)ENGINE = InnoDB;
CREATE TABLE `PROJECT_CANDIDATE` (
`CANDIDATE_ID` INT NULL ,
`PROJECT_ID` INT NULL ,
CONSTRAINT `FK_PROJECT_CANDIDATE`
FOREIGN KEY (`CANDIDATE_ID` )
REFERENCES `CANDIDATE` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
CONSTRAINT `FK_CANDIDATE_PROJECT`
FOREIGN KEY (`PROJECT_ID` )
REFERENCES `PROJECT` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)ENGINE = InnoDB;
Doctrine マッピングは次のようになります。
class Project
{
//.... other fields
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Candidate", mappedBy="projects", fetch="LAZY",cascade={"persist","merge"},orphanRemoval=true)
*/
private $candidates;
}
class Candidate
{
//.... other fields
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Project", inversedBy="candidates", fetch="LAZY",cascade={"persist","merge"},orphanRemoval=true)
* @ORM\JoinTable(name="project_candidate",
* joinColumns={
* @ORM\JoinColumn(name="CANDIDATE_ID", referencedColumnName="ID")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="PROJECT_ID", referencedColumnName="ID")
* }
* )
*/
private $projects;
}
私の質問は、なぜ次のようにプロジェクトから候補者を削除するのかということです:
//get $project with EntityManager
$project->candidates->clear();
また、 PROJECT_CANDIDATEがあるにもかかわらず、テーブルのエントリCandidates
が削除されますか?ON UPDATE/DELETE NO ACTION' for FK in