Created new entity Tag and migration to create new tables

This commit is contained in:
Alejandro Celaya
2016-08-21 09:41:21 +02:00
parent a2c2bc166c
commit 2ca7ab4ccf
3 changed files with 150 additions and 0 deletions

View File

@@ -42,6 +42,16 @@ class ShortUrl extends AbstractEntity implements \JsonSerializable
* @ORM\OneToMany(targetEntity=Visit::class, mappedBy="shortUrl", fetch="EXTRA_LAZY")
*/
protected $visits;
/**
* @var Collection|Tag[]
* @ORM\ManyToMany(targetEntity=Tag::class, cascade={"persist"})
* @ORM\JoinTable(name="short_urls_in_tags", joinColumns={
* @ORM\JoinColumn(name="short_url_id", referencedColumnName="id")
* }, inverseJoinColumns={
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
* })
*/
protected $tags;
/**
* ShortUrl constructor.
@@ -125,6 +135,34 @@ class ShortUrl extends AbstractEntity implements \JsonSerializable
return $this;
}
/**
* @return Collection|Tag[]
*/
public function getTags()
{
return $this->tags;
}
/**
* @param Collection|Tag[] $tags
* @return $this
*/
public function setTags($tags)
{
$this->tags = $tags;
return $this;
}
/**
* @param Tag $tag
* @return $this
*/
public function addTag(Tag $tag)
{
$this->tags->add($tag);
return $this;
}
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php

View File

@@ -0,0 +1,40 @@
<?php
namespace Shlinkio\Shlink\Core\Entity;
use Doctrine\ORM\Mapping as ORM;
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
/**
* Class Tag
* @author
* @link
*
* @ORM\Entity()
* @ORM\Table(name="tags")
*/
class Tag extends AbstractEntity
{
/**
* @var string
* @ORM\Column(unique=true)
*/
protected $name;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
}