From: Nicolas LÅ“uillet Date: Fri, 6 Feb 2015 14:18:54 +0000 (+0100) Subject: add a real relation between user and entry X-Git-Tag: 2.0.0-alpha.0~85^2~3 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=5f09650eef7bea52b7c54c074c0f873f96e53c86;p=github%2Fwallabag%2Fwallabag.git add a real relation between user and entry --- diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index a00762ca..937213b4 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -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; } /** diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index 6abfd3ae..cfbd57f8 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -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 + */ + public function getEntries() + { + return $this->entries; + } + /** * @inheritDoc */