[英]How to design Doctrine 2 Entities
I have two MySQL tables ( news
and news_lng
). 我有两个MySQL表(
news
和news_lng
)。 News table content id
, from_date
, to_date
and leading_image
fields. 新闻表
content id
, from_date
, to_date
和leading_image
字段。 news_lng
table contains id
, news_id
, lng
, title
and body
fields. news_lng
表包含id
, news_id
, lng
, title
和body
字段。
news
id | from_date | to_date | leading_image
1 | 2017-05-01 | 0000-00-00 | test.jpg
news_lng
id | news_id | lng | title | body
1 | 1 | en_GB | test | test body
2 | 1 | en_US | test | test content
How to design doctrine 2 entities ? 如何设计学说2实体?
1. 1。
/**
* @ORM\Entity(repositoryClass="\Admin\Repository\NewsRepository")
* @ORM\Table(name="news")
*/
class News {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id")
*/
protected $id;
/**
* @ORM\Column(name="from_date")
*/
protected $fromDate;
/**
* @ORM\Column(name="to_date")
*/
protected $toDate;
/**
* @ORM\Column(name="leading_image")
*/
protected $leadingImage;
/**
* @ORM\OneToMany(targetEntity="\Admin\Entity\NewsLng", fetch="EAGER", mappedBy="news_id")
*/
private $translations;
public function __construct() {
$this->translations = new ArrayCollection();
}
// getters and setters ...//
}
/**
* @ORM\Entity
* @ORM\Table(name="news_lng")
*/
class NewsLng {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="\Admin\Entity\News", inversedBy="translations", fetch="EAGER")
* @ORM\JoinColumn(name="news_id", referencedColumnName="id")
*/
protected $news_id;
/**
* @ORM\Column(name="lng")
*/
protected $lng;
/**
* @ORM\Column(name="title")
*/
protected $tile;
/**
* @ORM\Column(name="body")
*/
protected $body;
// getters and setters ...//
}
What are best practices in doctrine 2 ? 什么是学说2的最佳实践?
In your case using a relation is appropriate solution. 在您的情况下使用关系是适当的解决方案。 Table inheritance is designed for something else.
表继承是为其他东西设计的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.