2017-07-06 54 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關係
這意味着你正在做你的表連接