【问题标题】:Doctrine2 YAML schema - how to define primary key in centre of schema?Doctrine2 YAML 模式 - 如何在模式中心定义主键?
【发布时间】:2013-11-08 17:59:54
【问题描述】:

我每天使用 Doctrine 将远程 CSV 导入 MySQL。远程 CSV 的主键位于架构的中心,而不是位于开头或结尾。

这似乎使得使用原则将这个“id”分配为主键成为不可能。为了匹配,我必须保留这个主键。

    UKtradestransaction:
      type: entity
      repositoryClass: UktradesTransactionRepository
      table: uktrades_transactions
      fields:
        owner_id:
          type: integer
          length: 9
          nullable: true
        security_id:
          type: integer
          length: 9
        id:   # THIS NEEDS TO BE THE PRIMARY KEY
          type: integer
          length: 12
        exercise_price_uk:
          type: decimal
          length: 15
          scale: 4
          nullable: true
        update_date:
          type: date
          nullable: true
      id:
        id:  # THIS WILL NOT WORK 
          type: integer
          length: 12
          generator:
              strategy:auto

由于最终的 id 字段与中心的 id 重复,因此上述操作无效。

如何将中间的“id”字段指定为主键?有没有办法将'id'字段定义为'fields'定义中的内联主键?

【问题讨论】:

    标签: symfony doctrine-orm yaml


    【解决方案1】:

    我认为字段的顺序并不重要。 Doctrine 允许确定字段中的主键或before them,这是我个人更喜欢的语法。只需从字段列表中删除id,它仍将被视为一个字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-09
      • 2019-02-24
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      相关资源
      最近更新 更多