0

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.

Jason Roman
  • 8,146
  • 10
  • 35
  • 40
Zoltán Fekete
  • 504
  • 1
  • 6
  • 22

2 Answers2

0

You are reinventing the wheel, you have to use the DoctrineExtensions / Translatable behavior that will do the whole job for you:

  • Deal with model modifications, almost like what you are doing
  • Get directly the string in the correct language, when getting it
  • ...
flouflou2000
  • 201
  • 2
  • 5
  • These strings have to be editable in the admin panel, this is why these are in database. And of course its an old project and I don't have time for any refactoring or something. – Zoltán Fekete Jul 07 '17 at 08:52
-1

I want to explain to you something you should know.

Let's say that we have table A, table B, and table C.

and then

you want the table A, table B, and table C having relation without JOIN

I will tell you that it is imposible.


WHY ?

Actually, if table A, table B, and table C have a Relation,
it means that you are doing JOIN on your table.

Sherly Febrianti
  • 1,097
  • 15
  • 33