【问题标题】:Single Table Inheritance and Yaml configuration单表继承和 Yaml 配置
【发布时间】:2011-12-20 04:55:05
【问题描述】:

我想在我的项目中使用 symfony2/doctrine 的单表继承,但我找不到任何带有 yaml 配置的工作示例。在官方文档中,仅提供注释配置。我找到了 xml 示例,但我想使用 yaml 配置。有人可以帮忙分享一些工作代码吗?

【问题讨论】:

    标签: doctrine-orm symfony yaml


    【解决方案1】:

    这里是an example of YAML markup

    根据reference将实体配置文件放入src/Acme/StoreBundle/Resources/config/doctrine/<EntityName>.orm.yml

    也可以使用内置转换器:how to model inheritance in doctrine2 with yaml?

    【讨论】:

    【解决方案2】:

    好的内置转换器可以挽救生命。

    为了节省时间,这里将继承转换为 yaml 的示例:

    #file: Resources/config/doctrine/Person.orm.yml
    Person:
      type: entity
      table: null
      fields:
        id:
          type: integer
          id: true
          generator:
            strategy: AUTO
      inheritanceType: SINGLE_TABLE
      discriminatorColumn:
        name: discr
        type: string
        length: 255
      discriminatorMap:
        person: Person
        employee: Employee
      lifecycleCallbacks: {  }
    
    
    #file: Resources/config/doctrine/Employee.orm.yml
    Employee:
      type: entity
      table: null
      lifecycleCallbacks: {  }
    

    【讨论】:

    • 请注意,在 symfony 2.2 中,类不是由控制台的命令 'doctrine:generate:entities' 生成的,除非类是手动创建的。
    猜你喜欢
    • 2017-04-18
    • 2011-02-20
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多