Doctrine orm yml mapping ontToOne ReflectionException

时间:2014-10-24 07:28:31

标签: symfony orm doctrine-orm yaml one-to-one

我遇到了一个小问题,我尝试以一对一的关系映射我的实体。 我正在使用Doctrine 2.4和Symfony。 以下是我的实体:

Acme\DemoBundle\Entity\Foo:
  type: entity
  oneToOne:
    bar:
      targetEntity: Acme\DemoBundle\Entity\Bar
      joinColumn:
        name: bar_id
        referencedColumnName: id

  table: foo_params
  fields:
    id:
      id: true
      type: integer
      column: id
      generator:
        strategy: IDENTITY
    fooName:
      type: string
      length: 80
      nullable: false
      column: foo_name
      options:
        comment: name of the placeholder for this parameter
    fooType:
      nullable: false
      column: foo_type

Acme\DemoBundle\Entity\Bar:
  type: entity
  id:
    id:
      type: integer
      column: id
      generator:
        strategy: IDENTITY

当我在Symfony2上运行时出现的错误,例如迁移差异是:

  [ReflectionException]
  Property Acme\DemoBundle\Entity\Foo::$bar does not exist

我的代码有什么问题?

1 个答案:

答案 0 :(得分:1)

php app/console doctrine:generate:entities Acme\DemoBundle

然后

php app/console doctrine:schema:update --force

没有它就不会映射任何东西,格式无关紧要。