2017-07-06 101 views
0

我有以下表格:Symfony的一个一对多的单向关系,而不JOIN表

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) 

存储在一个表中的所有本地化的文本,并连接到该表中的每个其他表。

我不知道如何编写国家模式?这是我到目前为止的。

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实体获取国家或任何实体。但我不想制作一个连接表,因为它有点矫枉过正,而且毫无意义。

+0

为什么它是矫枉过正/毫无意义? –

+0

你想连接**公司**表与哪个表? –

+0

你可以看到我的答案。可能的答案可以给你一些启示。 –

回答

0

你重新发明轮子,你必须使用DoctrineExtensions/Translatable behavior会为你做整个工作:

  • 处理模型的修改,就像你在做什么
  • 获取直接在正确的语言字符串,当得到它
  • ...
+0

这些字符串必须在管理面板中可编辑,这就是为什么这些字符串在数据库中。当然,这是一个旧的项目,我没有时间进行任何重构或其他事情。 –

0

我想向你解释一些你应该知道的东西。

比方说,我们有table Atable Btable C

然后

你想要的table Atable Btable C关系没有JOIN

我会告诉你,这是IMPOSIBLE。


为什么?

其实,如果table Atable Btable C关系
这意味着你正在做你的表连接