0

我正在尝试在 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”会正常工作......

4

1 回答 1

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
于 2013-03-12T01:41:07.483 回答