代码之家  ›  专栏  ›  技术社区  ›  Dhia Eddine Farah

将属性添加到关联类ManyToMany

  •  1
  • Dhia Eddine Farah  · 技术社区  · 8 年前

    我使用Symfony和Doctrine映射数据库,我有两个实体“Product”和“Operation”,有许多关系,所以我在数据库中得到另一个表,称为“Products Operations”

    manyToMany:
        operations:
            targetEntity: Operation
            mappedBy: produits
    

    manyToMany:
        produits:
            targetEntity: Produit
            inversedBy: operations
            joinTable:
                name: produits_operations
                joinColumns:
                    operation_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    produit_id:
                        referencedColumnName: id
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Farshadi    8 年前

    我使用注释在数据库中创建表,我认为是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;
    }
    
    推荐文章