Search code examples
symfonydoctrine-ormmappingyamlbidirectional

Doctrine2 YML Mapping on Symfony2


I am starting with Symfony2, and so do I with Doctrine2.

I want to make an entity bidirectional, but I don't know what I am doing wrong. Here is my two .orm.yml files :

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

When I want to run the command :

doctrine:schema:update --dump-sql

I am getting this error :

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

If you guys have any hint on what I am doing wrong, I would be very grateful.

Thanks !


Solution

  • Are you sure you really have a property named "SousCategories" under your "Categorie" class? Would be nice if you could add your entity class in your first post.

    BTW, if it's a property, it shouldn't begin with an uppercase letter.