【问题标题】:Symfony project inheritance and sfguardSymfony项目继承和sfguard
【发布时间】:2012-04-26 10:46:42
【问题描述】:

这是我的 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_1user_type_2 组成,我希望他们都从 sfGuardUser 继承,如果我使用继承类型 concrete strong> 或 column_aggregation

谢谢

【问题讨论】:

    标签: doctrine symfony-1.4 sfguard


    【解决方案1】:

    你可以使用任何一种,这取决于你想要什么。 来自docs

    混凝土
    具体继承为子类创建单独的表。然而,在具体继承中,每个类都会生成一个包含所有列(包括继承的列)的表。为了使用具体继承,您需要向子类添加显式 parent::setTableDefinition() 调用,如下所示。

    列聚合
    在下面的示例中,我们有一个名为 entity 的数据库表。用户和组都是实体,它们共享同一个数据库表。 实体表有一个名为 type 的列,它告诉实体是组还是用户。然后我们决定用户是类型 1,组是类型 2。 我们唯一要做的就是创建 3 条记录(和之前一样),然后从父类中添加对 Doctrine_Table::setSubclasses() 方法的调用。

    使用具体继承会创建 2 个表(user_type_1 和 user_type_2),而 column_aggregation 只会创建 1 个具有“类型”列的表。

    【讨论】:

      猜你喜欢
      • 2011-10-18
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 2016-07-30
      相关资源
      最近更新 更多