현재 새로운 애플리케이션을 설정 중이며 doctrine2를 orm으로 사용하기로 결정했습니다. 나는 doctrine2에 익숙하지 않고, 내가 원하는 방식으로 내 디자인을 얻는 데 어려움을 겪고있다.Doctrine2 상속 문제 디자인하기
이 내가 할 노력하고있어입니다 :
나는 다음과 같은 클래스가 :
class User {
protected $userid;
protected $role;
protected $lang;
protected $email;
protected $disabled;
...
+ getters and setters
}
class Person extends User {
protected $personid;
protected $name;
protected $firstname;
protected $company;
protected $functiontitle
...
+ getters and setters
}
class Candidate extends User {
protected $candidateid;
protected $name;
protected $firstname;
protected $title;
protected $birthdate;
...
+ getters and setters
}
후보 모두와 사람이 사용자의 속성을 상속하지만, 자신의 집합 연산 특정 속성을 가지고있다.
postgresql 데이터베이스에서 필자는 비슷한 셋업, 3 개의 테이블, 각각의 특정 컬럼 세트를 가지고 있습니다.
이제 이것을 yaml을 사용하여 매핑하고 모든 3 개의 클래스를 엔티티로 액세스 할 수있게하려고합니다. 또한 데이터베이스에 많은 필드를 복제하고 싶지 않습니다. 어떻게해야합니까? 저는 며칠 동안 해결책을 찾고 있었지만 작동하는 것은 없었습니다.
내가 수행하려는 작업이 불가능한 경우 내 옵션이 무엇이며 왜 지원되지 않는지 설명하십시오. ORM이 없으면 후보 테이블과 사용자 테이블에 외래 키를 쉽게 추가 할 수 있지만 교리를 사용할 수는 없습니다. 사용자 :
MyProject\model\User:
type: entity
table: `user`
id:
userid:
column: userid
type: integer
nullable: false
comment: ''
id: true
fields:
role:
column: role
type: string
nullable: true
length: null
fixed: false
comment: ''
email:
type: string
nullable: true
length: null
fixed: false
comment: ''
disabled:
type: boolean
nullable: true
comment: ''
InheritanceType: JOINED
DiscriminatorColumn:
name: discr
type: string
DiscriminatorMap:
person: Person
candidate: Candidate
lifecycleCallbacks: { }
담당자 :
MyProject\model\Person:
type: entity
table: person
fields:
name:
type: string
nullable: true
length: null
fixed: false
comment: ''
firstname:
type: string
nullable: true
length: null
fixed: false
comment: ''
company:
type: string
nullable: true
length: null
fixed: false
comment: ''
functiontitle:
type: string
nullable: true
length: null
fixed: false
comment: ''
...
lifecycleCallbacks: { }
는하지만이 작동하지 않는
이
내가 현재 클래스 테이블 상속로 설정해야하는 YAML 파일입니다.
D2 상속을 살펴보십시오. http://doctrine-orm.readthedocs.org/en/latest/reference/inheritance-mapping.html#class-table-inheritance – Cerad
저는 현재 가지고있는 것과 같이 설정했습니다. 이,하지만 지금은 내 userentity의 필드 (즉 "역할")가 내 사람 - 테이블의 열로 존재하지 않는 오류가 발생합니다. 그들이 내 사용자 테이블에 있기 때문에 내 사람 - 테이블에 그들을 원하지 않기 때문에 올바른 것입니다. –
삭제 된 맵핑 파일로 질문을 업데이트하십시오. 글쎄 그건 빨리했다. 3 개의 테이블의 경우, 단일 테이블 상속이 아니라 클래스 테이블 상속을 사용하고자합니다. 단일 테이블은 모든 것을 하나의 테이블에 넣습니다. – Cerad