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.
You are reinventing the wheel, you have to use the DoctrineExtensions / Translatable behavior that will do the whole job for you: