我开始使用Symfony,我发现了一些关于继承的文档。但也发现this discouraging article,这让我怀疑,如果教义继承处理任何好...symfony + doctrine +继承,如何让它们工作?
有没有人找到一个聪明的解决方案继承在Symfony + Doctrine?
举个例子,我已经结构化的数据库是这样的:
CREATE TABLE `poster` (
`poster_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(50) NOT NULL,
PRIMARY KEY (`poster_id`),
UNIQUE KEY `id` (`poster_id`),
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
CREATE TABLE `user` (
`user_id` int(11) NOT NULL,
`real_name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_id` (`user_id`),
CONSTRAINT `user_fk` FOREIGN KEY (`user_id`) REFERENCES `poster` (`poster_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
从这一点,学说产生这一 “的schema.yml”:
Poster:
connection: doctrine
tableName: poster
columns:
poster_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
user_name:
type: string(50)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Post:
local: poster_id
foreign: poster_id
type: many
User:
local: poster_id
foreign: user_id
type: many
Version:
local: poster_id
foreign: poster_id
type: many
User:
connection: doctrine
tableName: user
columns:
user_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: false
real_name:
type: string(50)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Poster:
local: user_id
foreign: poster_id
type: one
用户创建了这种结构与Doctrine自动生成的表单不起作用。
任何线索将不胜感激。
我很困惑你想如何应用基于上述数据的继承(你原来的SQL与生成的.yml没有关联)。你能详细说明你想做什么吗? – richsage 2010-05-05 20:33:26
感谢您的回答。 那么,它应该相互关联,因为它是由Doctrine生成的。我确实把它聚焦在这个问题上。我只是发现海报表的关系很奇怪,因为那些是从其他表到海报表的外部FK ... 我只是试图扩展Poster与用户,这就是为什么我让user_id成为poser_id的FK。请告诉我,如果我需要更具体。 – ismaelmachado 2010-05-06 02:04:08
嗯,我现在看到了('版'的东西让我困惑)。如果你首先在.yml中编写模式,可能会更容易 - 我不明白为什么Doctrine会生成这些其他关系,除非您是从已经有FK的数据库自动生成的。 – richsage 2010-05-06 08:18:22