【问题标题】:Problems with Doctrine 2 CRUD generator and identifier which isn't called "id"Doctrine 2 CRUD 生成器和不称为“id”的标识符的问题
【发布时间】:2012-08-01 02:17:11
【问题描述】:

情况如下: 我是 Symfony2 的新手并且喜欢它,但我遇到了 Doctrine 的 CRUD 生成器的问题。我已经从 YAML 文件开始使用 Doctrine 生成实体,但无法使用doctrine:generate:crud 命令行生成它们的CRUD。

问题: 出于某种原因,我需要设置一个 'id' 字段和一个 getId() 方法,但这有点毁了我在类图和关系模式上所做的所有工作......

我的问题是: 有没有办法让我的字段名称保持原样并让 Doctrine 仍然生成我的 CRUD?

一个 YAML 示例:

XXX\XXXBundle\Entity\Utilisateur:
 type: entity
 table: utilisateur
 id:
  pseudo:
   type: string
 fields:
  nom:
   type: string

我被这个困住了……我试图改变它:

XXX\XXXBundle\Entity\Utilisateur:
 type: entity
 table: utilisateur
 fields:
  pseudo: # Le pseudo correspond au nom affiché pour identifier un utilisateur.
   type: string
   id: true

但这并没有改变任何事情我总是最终得到这个:

[RuntimeException]                                                                                      
The CRUD generator expects the entity object has a primary key field named "id" with a getId() method.

如果有人能提供帮助,我将不胜感激!在最坏的情况下,我将不得不修改我的所有实体以添加一个带有自动生成整数的愚蠢 ID 字段……

【问题讨论】:

    标签: doctrine-orm symfony-2.1


    【解决方案1】:

    不,这是不可能的。

    已经有一个变更请求: https://github.com/sensio/SensioGeneratorBundle/issues/57

    在第 69 - 71 行的DoctrineCrudGenerator.php 中硬编码:

    if (!in_array('id', $metadata->identifier)) {
        throw new \RuntimeException('The CRUD generator expects the entity object has a primary key field named "id" with a getId() method.');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      相关资源
      最近更新 更多