프로젝트에 대한 ER 모델을 만들고 PHP로 구현하고 다음 매핑 정보를 추가했습니다.외래 키를 포함하는 합성 기본 키를 가진 doctrine을 사용하여 객체를 유지할 수 없습니다.
AppBundle\Entity\Competition:
type: entity
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
location:
date:
type: datetime
lifecycleCallbacks: { }
oneToMany:
runs:
targetEntity: Run
mappedBy: comp
cascade: [persist]
,
AppBundle\Entity\Run:
type: entity
id:
id:
type: integer
comp:
associationKey: true
fields:
name:
lifecycleCallbacks: { }
manyToOne:
comp:
targetEntity: Competition
inversedBy: runs
및
AppBundle\Entity\Participate:
type: entity
id:
athlete:
associationKey: true
run:
associationKey: true
comp:
associationKey: true
fields:
number:
type: integer
lifecycleCallbacks: { }
manyToOne:
athlete:
targetEntity: Athlete
cascade: [persist]
run:
targetEntity: Run
cascade: [persist]
comp:
targetEntity: Run
cascade: [persist]
편집 : 실행은 우리가해야한다 ak Entity, 그래서 나는 Run에 2 개의 관계가 필요하다고 생각한다. 첫 번째 경기는 경기에, 두 번째 경기는 두 번째 경기에 속합니다.
경쟁 작업과 실행이 매력처럼 작동, 나는 계속 그들을 가져올 수 있지만, 최대한 빨리하려고으로 참여의 객체를 지속 할 수 있습니다, 나는 다음과 같은 오류 얻을 : 내가 사용하는
Binding an entity with a composite primary key to a query is not supported. You should split the parameter into the explicit fields and bind them separately.
을 다음 코드 :
$em = $this->getDoctrine()->getManager();
$em->persist($participate);
$em->flush();
이 문제를 해결하려면 무엇을해야할지 모르겠다.
감사
EDIT2 :이 Run
이미하고 Run
객체가 고유로 그 이론적, 내가 Participate
에 관계 comp
필요하지 않습니다
난 그냥 이해.
ALTER TABLE Participate DROP FOREIGN KEY FK_8B9E3EEF4D0D3BCB;
DROP INDEX IDX_8B9E3EEF4D0D3BCB ON Participate;
ALTER TABLE Participate DROP PRIMARY KEY;
ALTER TABLE Participate DROP comp_id;
ALTER TABLE Participate ADD PRIMARY KEY (athlete_id, run_id);
Participate
에 Competition
에 외래 키를 제거 할 것이다 : 나는 그에 따라 내 데이터베이스를 업데이트 할 경우에, 교리 나에게 다음과 같은 SQL을 제공합니다. 그러나 run_id
은 약한 키이어야하기 때문에 고유하지 않습니다. 2 개 manyToOne 관계가 경화제가 targrtEntity "경쟁"이 있어야 targetEntity
AppBundle\Entity\Participate
manyToOne:
run: targetEntity: Run
comp: targetEntity: Run
을 동일한 개체를 가지고 있기 때문에
그러나 이것은 참여와 경쟁 사이의 관계를 만들 것입니다. 그러나 참여는 오직 복합적인 PK가있는 Run과 관련이 있어야합니다. – exastion
그렇다면 중개 엔티티를 만들어 두 번 사용하지 않는 이유는 무엇입니까? – user3504263
나는 정말로 이해하지 못한다. 질문에 정보를 추가했습니다. – exastion