]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
add a real relation between user and entry
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Fri, 6 Feb 2015 14:18:54 +0000 (15:18 +0100)
committerJeremy <jeremy.benoist@gmail.com>
Sun, 8 Feb 2015 22:13:40 +0000 (23:13 +0100)
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Entity/User.php

index a00762cadfbc1a58a4250f09b1e803529fbd71af..937213b4477b85f294bf143529eaf38d032672e0 100644 (file)
@@ -81,13 +81,6 @@ class Entry
      */
     private $updatedAt;
 
-    /**
-     * @var string
-     *
-     * @ORM\Column(name="user_id", type="decimal", precision=10, scale=0, nullable=true)
-     */
-    private $userId;
-
     /**
      * @var string
      *
@@ -123,6 +116,19 @@ class Entry
      */
     private $isPublic;
 
+    /**
+     * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
+     */
+    private $user;
+
+    /*
+     * @param User     $user
+     */
+    public function __construct(User $user)
+    {
+        $this->user = $user;
+    }
+
     /**
      * Get id
      *
@@ -263,26 +269,11 @@ class Entry
     }
 
     /**
-     * Set userId
-     *
-     * @param  string $userId
-     * @return Entry
-     */
-    public function setUserId($userId)
-    {
-        $this->userId = $userId;
-
-        return $this;
-    }
-
-    /**
-     * Get userId
-     *
-     * @return string
+     * @return User
      */
-    public function getUserId()
+    public function getUser()
     {
-        return $this->userId;
+        return $this->user;
     }
 
     /**
index 6abfd3ae46374f2080c87d6ebcb25dea14b5c458..cfbd57f8835049f19b52d5497906b92e0e37a28b 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Wallabag\CoreBundle\Entity;
 
+use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Security\Core\User\AdvancedUserInterface;
@@ -78,10 +79,16 @@ class User implements AdvancedUserInterface, \Serializable
      */
     private $updatedAt;
 
+    /**
+     * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
+     */
+    private $entries;
+
     public function __construct()
     {
         $this->isActive = true;
-        $this->salt = md5(uniqid(null, true));
+        $this->salt     = md5(uniqid(null, true));
+        $this->entries  = new ArrayCollection();
     }
 
     /**
@@ -231,6 +238,26 @@ class User implements AdvancedUserInterface, \Serializable
         return $this->updatedAt;
     }
 
+    /**
+     * @param Entry $entry
+     *
+     * @return User
+     */
+    public function addEntry(Entry $entry)
+    {
+        $this->entries[] = $entry;
+
+        return $this;
+    }
+
+    /**
+     * @return ArrayCollection<Entry>
+     */
+    public function getEntries()
+    {
+        return $this->entries;
+    }
+
     /**
      * @inheritDoc
      */