只是doctrine .orm文件中的最后一个关系正在运行

时间:2013-03-11 17:11:15

标签: doctrine-orm doctrine

我正试图在Doctrine中建立一些关系

LancamentoConf.orm.yml:

Amz\FinanceiroBundle\Entity\LancamentoConf:
  type: entity
  table: amz_financeiro_lancamento_conf
  id:
    id:
      type: integer
      generator: { strategy: AUTO }
  fields:
    active:
      type: string
      length: 1
  ...
  manyToOne:
    conta:
      targetEntity: ContaConf
      inversedBy: contajoinlancamentoconf
      joinColumn:
        name: amz_financeiro_conta_conf_id
        referencedColumnName: id
  manyToOne:
    centrodecusto:
      targetEntity: Amz\AmzBundle\Entity\CentroDeCustoConf
      inversedBy: lancamentoconf
      joinColumn:
        name: amz_centro_de_custo_conf_id
        referencedColumnName: id

ContaConf.orm.yml:

Amz\FinanceiroBundle\Entity\ContaConf:
  type: entity
  table: amz_financeiro_conta_conf
  id:
    id:
      type: integer
      generator: { strategy: AUTO }
  fields:
    active:
      type: string
      length: 1
  ...
  oneToMany:
    contajoinlancamentoconf:
      targetEntity: LancamentoConf
      mappedBy: lancamentoconf

但只是“centrodecusto”关系正在发挥作用......

我注意到LancamentoConf.orm.yml中的最后一个关系有效。如果我改变顺序(“centrodecusto”第一次和“conta”第二次),“centrodecusto”将正常工作......

1 个答案:

答案 0 :(得分:0)

你的问题是重复的manyToOne部分,应该只有一个定义,你可以在里面定义几个元素:

LancamentoConf.orm.yml:

Amz\FinanceiroBundle\Entity\LancamentoConf:
  type: entity
  table: amz_financeiro_lancamento_conf
  id:
    id:
      type: integer
      generator: { strategy: AUTO }
  fields:
    active:
      type: string
      length: 1
  ...
  manyToOne:
    conta:
      targetEntity: ContaConf
      inversedBy: contajoinlancamentoconf
      joinColumn:
        name: amz_financeiro_conta_conf_id
        referencedColumnName: id
    centrodecusto:
      targetEntity: Amz\AmzBundle\Entity\CentroDeCustoConf
      inversedBy: lancamentoconf
      joinColumn:
        name: amz_centro_de_custo_conf_id
        referencedColumnName: id