]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Entity/Entry.php
add relation between entry and tag
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
index e47848b61d9bd93bf9105af7d63a23ac43d6ca49..e0d1b839c6a43d0a6100238d9e057b3797d08514 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Wallabag\CoreBundle\Entity;
 
+use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 use Hateoas\Configuration\Annotation as Hateoas;
@@ -118,12 +119,22 @@ class Entry
      */
     private $user;
 
+    /**
+     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist", "merge"})
+     * @ORM\JoinTable(name="tags_entries",
+     *   joinColumns={@ORM\JoinColumn(name="entry_id", referencedColumnName="id")},
+     *   inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
+     * )
+     */
+    private $tags;
+
     /*
      * @param User     $user
      */
     public function __construct(User $user)
     {
         $this->user = $user;
+        $this->tags = new ArrayCollection();
     }
 
     /**
@@ -381,4 +392,20 @@ class Entry
     {
         $this->isPublic = $isPublic;
     }
+
+    /**
+     * @return ArrayCollection<Tag>
+     */
+    public function getTags()
+    {
+        return $this->tags;
+    }
+
+    /**
+     * @param Tag $tag
+     */
+    public function addTag(Tag $tag)
+    {
+        $this->tags[] = $tag;
+    }
 }