这是我的Schema.yml的正确语法吗?
user_type_1 :
inheritance:
type: concrete
extends: sfGuardUser
columns:
name: { type: string(255) }
user_type_2 :
inheritance:
type: concrete
extends: sfGuardUser
columns:
name: { type: string(255) }
我的项目由两种类型的用户 user_type_1 和 user_type_2 组成,我希望他们都从sfGuardUser继承,shoud我使用继承类型具体或 column_aggregation
THX
答案 0 :(得分:0)
你可以使用任何一个,这取决于你想要什么。 来自docs:
具体
具体继承为子类创建单独的表。但是在具体继承中,每个类都会生成一个包含所有列(包括继承列)的表。为了使用具体的继承,你需要向子类添加显式的parent :: setTableDefinition()调用,如下所示。
列聚合
在以下示例中,我们有一个名为entity的数据库表。用户和组都是实体,它们共享同一个数据库表。
实体表有一个名为type的列,用于指示实体是组还是用户。然后我们决定用户是类型1和组类型2。
我们唯一要做的就是创建3条记录(与之前相同),并从父类中添加对Doctrine_Table :: setSubclasses()方法的调用。
使用具体继承将创建2个表(user_type_1和user_type_2),而column_aggregation将仅创建1个带有“type”列的表。