【问题标题】:Doctrine "relation does not exist" error教义“关系不存在”错误
【发布时间】:2017-10-12 19:13:37
【问题描述】:

我有两个通过 CompanySupplier 实体链接在一起的原则实体(公司和供应商)。实体和yaml资源如下:

class Company
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

}

class Supplier
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

}    

class CompanySupplier
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var integer
     */
    private $company_id;

    /**
     * @var integer
     */
    private $supplier_id;

}

我的资源如下:

AppBundle\Entity\Company:
  type: entity
  table: companies
  id:
    id:
      type: integer
  fields:
    name:
      type: string
  manyToMany:
    Suppliers:
      targetEntity: Supplier
      joinTable:
        name: company_suppliers
        joinColumns:
          company_id:
            referencedColumnName: id
        inverseJoinColumns:
          supplier_id:
            referencedColumnName: id


AppBundle\Entity\Supplier:
  type: entity
  table: suppliers
  id:
    id:
      type: integer
  fields:
    name:
      type: string

AppBundle\Entity\CompanySupplier:
  type: entity
  table: company_suppliers
  id:
    id:
      type: integer
  fields:
    company_id:
      type: integer
    supplier_id:
      type: integer
  ManyToMany:
    Supplier:
      targetEntity: Supplier
      joinColumn:
        name: id
        referencedColumnName: supplier_id

问题是这似乎导致“关系公司_供应商不存在”错误,我不知道如何解决。我需要做些什么来建立关系才能使它们起作用?

如果我没有 CompanySupplier 实体和资源,它会起作用,但是一旦我定义这些错误就会开始出现。

如果有任何让我发疯的指点,我将不胜感激。

【问题讨论】:

    标签: symfony doctrine-orm


    【解决方案1】:

    改变命名空间,你不需要写我认为的关系表 see here

    Company:
      type: entity
      manyToMany:
        supplier:
          targetEntity: CompanySupplier
          inversedBy: company
          joinTable:
            name: company_suppliers
            joinColumns:
              name: id
              referencedColumnName: supplier_id
            inverseJoinColumns:
              supplier_id:
                referencedColumnName: id
    
    Supplier:
      type: entity
      manyToMany:
        company:
          targetEntity: Company
          mappedBy: supplier
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-22
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多