I have the following tables:
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)
All localizable text stored in a single table, and every other table connected to that table.
What I dont know is how to write the Country model? This is how I got so far.
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();
}
}
Because of the structure you can't get the Country or any Entity from the StringText entity. But I don't want to make a join table, because its kind of an overkill, and totally meaningless.
I want to explain to you something you should know.
Let's say that we have
table A
,table B
, andtable C
.
and then
you want the
table A
,table B
, andtable C
having relation without JOIN
I will tell you that it is imposible.
WHY ?
Actually, if
table A
,table B
, andtable C
have a Relation ,
it means that you are doing JOIN on your table.
You are reinventing the wheel, you have to use the DoctrineExtensions / Translatable behavior that will do the whole job for you:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.