我使用 Symfony 和 Doctrine 映射数据库,我有 2 个实体“Product”和“Operation”,它们具有 ManyToMany 关系,所以我在数据库中得到另一个名为“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
最佳答案
我使用注释在数据库中创建表我认为相同的 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;
}
关于php - 将属性添加到关联类 ManyToMany,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45512260/