dsh7623
2015-06-08 13:56
浏览 52
已采纳

使用doctrine ORM(Symfony)正确创建ManyToMany递归/反身关系

I have this entity named Pointscomptage.php:

class Pointscomptage

    {
        /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer", nullable=false)
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="IDENTITY")
         */
        private $id;

        /**
         * @var string
         *
         * @ORM\Column(name="invariant", type="string", length=150, nullable=false)
         */
        private $invariant;

        /**
         * @var string
         *
         * @ORM\Column(name="nom", type="string", length=150, nullable=false)
         */
        private $nom;

        /**
         * @var string
         *
         * @ORM\Column(name="consoProduction", type="string", length=150, nullable=false)
         */
        private $consoProduction;

        /**
         * @var Typesenergie
         *
         * @ORM\ManyToOne(targetEntity="Typesenergie", inversedBy="pointscomptage")
         * @ORM\JoinColumn(name="typesenergie_id", referencedColumnName="id")
         */
        private $typesenergie;

        /** ... getters and setters */

I need to understand how to create a ManyToMany recursive or reflexive relation on this entity.

That is to say, a Pointscomptage could have no (0) or many (n) Pointscomptage.

How to make this relation on this same entity?


EDIT

Thanks to Jovan Perovic answer and suggestion this the solution I found, we need to respect doctrine annotation:

/**
     * @ORM\ManyToMany(targetEntity="Pointscomptage")
     * @ORM\JoinTable(name="pointscomptage_link_table",
     * joinColumns={
     *     @ORM\JoinColumn(name="pointscomptage_id", referencedColumnName="id")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="id_pointscomptage2", referencedColumnName="id")
     *   }
     * )
     **/
    private $pointscomptages;

Thank you a lot.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题