我使用Symfony和Doctrine来映射数据库,我有2个实体"产品"和"操作"与ManyToMany关系,所以我得到DataBase中的另一个表名为" Products-Operations"
现在我想为这个表添加一个属性,我该怎么办?
Produit.orm.yml
manyToMany:
operations:
targetEntity: Operation
mappedBy: produits
Operation.orm.yml
manyToMany:
produits:
targetEntity: Produit
inversedBy: operations
joinTable:
name: produits_operations
joinColumns:
operation_id:
referencedColumnName: id
inverseJoinColumns:
produit_id:
referencedColumnName: id
答案 0 :(得分:1)
我使用注释来创建数据库中的表我认为同样的orm.yml并希望这个解决方案是有效的...
//inverse side
class Product
{
/**
* @ORM\OneToMany(targetEntity="ProductOperation", mappedBy="product", cascade={"persist", "remove"})
*/
private $productOperations;
}
//owing side
class ProductOperation
{
/**
* @ORM\ManyToOne(targetEntity="Product", inversedBy="productOperations")
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity="Operation", inversedBy="productOperations")
*/
private $operation;
}
//inverse side
class Operation
{
/**
* @ORM\OneToMany(targetEntity="ProductOperation", mappedBy="operation", cascade={"persist", "remove"})
*/
private $productOperations;
}