我有两个由公司供应商实体链接在一起的学说实体(公司和供应商)。实体和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
问题是这似乎导致“关系company_supplier不存在”错误,我无法看到如何解决。我需要做些什么来设置关系才能使这些工作起作用?
如果我没有CompanySupplier实体和资源,它就有效,但是一旦我定义了这些错误就会开始出现。
我很感激任何指责这让我发疯。
答案 0 :(得分:0)
确实更改名称空间,我不需要编写关系表 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