0

我有以下表格:

strings
------
"id" int not null primary key

string_texts
------
"id"          int not null primary key
"string_id"   int not null fk(strings.id)
"language_id" int not null fk(languages.id)
"text"        text

"countries"
------
"id"      int not null primary key,
"name_id" int not null fk(strings.id)

所有可本地化的文本都存储在一个表中,以及连接到该表的所有其他表。

我不知道如何编写 Country 模型?这就是我到目前为止的方式。

namespace LoginHood\HoodBundle\Entity\Geo;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

class Country
{
    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     */
    protected $id;

    /**
     * @var Collection
     *
     * @ORM\OneToMany(targetEntity="StringText", mappedBy="")
     */
    protected $names;

    /*
    ...
    */


    public function __construct()
    {
        $this->names = new ArrayCollection();
    }
}

由于结构的原因,您无法从 StringText 实体获取 Country 或任何实体。但我不想制作一个连接表,因为它有点矫枉过正,而且完全没有意义。

4

2 回答 2

0

您正在重新发明轮子,您必须使用DoctrineExtensions / Translatable 行为来为您完成整个工作:

  • 处理模型修改,就像你正在做的一样
  • 获取时直接获取正确语言的字符串
  • ...
于 2017-07-06T22:35:36.593 回答
-1

我想向你解释一些你应该知道的事情。

假设我们有table Atable Btable C

接着

你想要table A, table B, 和table C没有JOIN关系

我会告诉你这是不可能的。


为什么 ?

实际上,如果 table Atable Btable C有一个Relation
这意味着你正在你的桌子上做JOIN 。

于 2017-07-06T16:30:31.793 回答