我試圖在原則中的答案和問題表之間創建OneToMany關係。這些都是基本的YAML模式關係原則中生成的唯一鍵
回答架構
type: entity
table: fs_answer
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
questionId:
type: integer
unsigned: false
nullable: false
column: question_id
body:
type: text
nullable: false
oneToOne:
question:
targetEntity: FsQuestion
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
question_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
問題的模式:
type: entity
table: fs_question
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
body:
type: text
nullable: false
oneToMany:
answer:
targetEntity: FsAnswer
cascade: { }
mappedBy: question
inversedBy: answers
joinColumns:
question_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
當我更新doctrine:schema:update
架構,它產生下面的SQL代碼,並把爲 'question_id'答案表。
CREATE TABLE IF NOT EXISTS `fs_answer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`question_id` int(11) NOT NULL,
`body` longtext NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_552D082B1E27F6BF` (`question_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
如何避免這個獨特的關鍵東西?邏輯上(一對多)在答案表中不應該有問題ID的唯一鍵。
對,每個答案只有一個問題。其實外交工作,但是,我不想要的唯一的鑰匙 – seferov 2012-03-07 16:17:33
同樣,你在講述主義從問題的答案到建立OnetoOne關係,同時從問題創建OneToMany來回答。只是不去工作。將OneToOne更改爲ManyToOne並確保正確定義了joinColumn。 – Cerad 2012-03-07 16:46:51