【问题标题】:Doctrine2 YML Mapping on Symfony2Symfony2 上的 Doctrine2 YML 映射
【发布时间】:2013-12-18 02:09:42
【问题描述】:

我是从 Symfony2 开始的,我也是从 Doctrine2 开始的。

我想使实体双向,但我不知道我做错了什么。这是我的两个 .orm.yml 文件:

Categorie.orm.yml:

MY\SUPERBundle\Entity\Categorie:
  type: entity
  fields:
    id:
      id: true
      type: integer
      generator:
        strategy: AUTO
    nomCategorie:
      type: text
      nullable: true
      column: NomCategorie
  oneToMany:
    SousCategories:
      targetEntity: MY\SUPERBundle\Entity\SousCategorie
      mappedBy: Categorie

SousCategorie.orm.yml:

MY\SUPERBundle\Entity\SousCategorie:
  type: entity
  fields:
    id:
      id: true
      type: integer
      generator:
        strategy: AUTO
    nomSousCategorie:
      type: text
      nullable: true
      column: NomSousCategorie
  manyToOne:
    Categorie:
      targetEntity: MY\SUPERBundle\Entity\Categorie
      inversedBy: SousCategories
      joinColumns:
        categorie_id:
          referencedColumnName: id
          nullable: false

当我想运行命令时:

doctrine:schema:update --dump-sql

我收到此错误:

 [ReflectionException]
  Property MY\SUPERBundle\Entity\Categorie::$SousCategories does not exist

如果你们对我做错了什么有任何提示,我将非常感激。

谢谢!

【问题讨论】:

  • 这似乎不是解决方案,但您的属性“SousCategories”不应大写。

标签: symfony doctrine-orm mapping yaml bidirectional


【解决方案1】:

您确定您的“Categorie”类下确实有一个名为“SousCategories”的属性吗? 如果您可以在第一篇文章中添加实体类,那就太好了。

顺便说一句,如果它是一个属性,它不应该以大写字母开头。

【讨论】:

  • 没错。我没有在“类别”类下添加名为“SousCategories”的属性。它应该叫什么名字?我的意思是,私人@sousCategories 是否足够好?
  • 是的,带有访问器的私有 sousCategories 类属性就足够了 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-18
  • 1970-01-01
  • 1970-01-01
  • 2017-03-03
  • 1970-01-01
相关资源
最近更新 更多