我试图在原则中的答案和问题表之间创建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