리스 클래스의 속성과의 다수의 관계
-
05-07-2019 - |
문제
저는 현재 교리와 함께 Symfony (1.2)를 사용하여 웹 사이트를 디자인하고 있습니다.
저녁 식사 수업, 기준 수업 및 Mark 클래스가 있습니다.
- 마크는 저녁 식사 및 기준과 연결되어 있으며 Dateofmark, MarkValue 등과 같은 개인 속성이 있습니다.
- 저녁 식사 및 기준에는 많은 마크가있을 수 있습니다 (또는 없음).
교리를 사용하면 다음 코드를 사용하여 Schema.yml 에서이 모델을 정의합니다.
Dinner:
columns:
date: { type: timestamp, notnull: true }
nb_presents: { type: integer, notnull: true }
relations:
Marks:
class: Criteria
local: dinner_id
foreign: criteria_id
refClass: Mark
Criteria:
columns:
name: { type: string(50), notnull: true }
relation:
Marks:
class: Dinner
local: criteria_id
foreign: dinner_id
refClass: Mark
Mark:
columns:
criteria_id: { type: integer, primary: true }
dinner_id: { type: integer, primary: true }
value: { type: integer, notnull: true }
relations:
Dinner:
local: dinner_id
foreign: id
Criteria:
local: criteria_id
foreign: id
문제는 교리에 의해 생성 된 SQL이 추가된다는 것입니다. FOREIGN KEY CONSTRAINT
~에 Mark.dinner_id
에게 Dinner.id
(맞습니다) 그리고 a FOREIGN KEY CONSTRAINT
~에 Dinner.id
에게 Mark.dinner_id
(저녁 식사에 많은 자국이있을 수 있으므로 실제로 틀 렸습니다).
의문
내가 뭐 놓친 거 없니 ? 수업간에 이런 종류의 관계를 잘못하고 있습니까?
감사해요.
해결책
관계를 일대일 관계로 정의해야합니다. 이것을 시도하십시오 (주석 : 많은 "저녁 식사 및 기준 정의에 추가) :
Dinner:
columns:
date: { type: timestamp, notnull: true }
nb_presents: { type: integer, notnull: true }
relations:
Marks:
class: Criteria
local: dinner_id
foreign: criteria_id
refClass: Mark
type: many
Criteria:
columns:
name: { type: string(50), notnull: true }
relation:
Marks:
class: Dinner
local: criteria_id
foreign: dinner_id
refClass: Mark
type: many
Mark:
columns:
criteria_id: { type: integer, primary: true }
dinner_id: { type: integer, primary: true }
value: { type: integer, notnull: true }
relations:
Dinner:
local: dinner_id
foreign: id
Criteria:
local: criteria_id
foreign: id
제휴하지 않습니다 StackOverflow