1

let's say I have the model 'Pages' that has :name, :content, :title ...etc

one of my requirements is that each of those attributes needs to be in 3 languages, and since those pages are to be stored in the db, using flat i18n files is out of the question

my solution in the past was to use a two tables and a join:

pages:
id name

pages_meta:
page_id title content language_id

in plain SQL i would be selecting:

 SELECT * FROM pages p LEFT JOIN pages_meta pm ON p.id = pm.page_id
 WHERE language_id = (server_variable for current language)

how I can achieve that in model in either rails or fuelphp (I'm using fuelphp for this project and rails for a different one but the issue is the same, and I'm not asking about how to code it, just how i would go about achieving this, or I would have to not use the orm and just go with plain SQL ?) I can use the many_to_many or has_many relationships, but I think that will introduce complexity dealing with each model as many since it's all the same data at the end
EDIT : ORM => Object Relational-Mapping, FuelPHP is the name of an HMVC library in PHP

EDIT 2 :
FuelPHP ORM database schema for i18n, opinions/suggestions
I'm fully aware of this related question, however the three solutions he's suggesting, aren't exactly what I'm looking for, I'm looking for a way to store data in different tables, and handle them as the same model, even tho I'm primarily interested in language, there are other cases in which I want the data separated

also for rails there is a gem called globalize that can i18n-ize the fields of an ORM model, but still not using different tables

Community
  • 1
  • 1
Qchmqs
  • 1,803
  • 2
  • 20
  • 29
  • I don't get you ?, you mean a base model then inherit from it ? – Qchmqs Jan 19 '17 at 09:39
  • What about serializing this data to an attribute like `translations` in the `Page` model? You can then keep the data for each language there like a hash (key is country code, value is the translated string) or any other data structure you want. You can use Postgres HStore type for this. – Ignacy Kasperowicz Jan 19 '17 at 11:24
  • that's a different way of doing this, that's not compatible with the rest of my structure – Qchmqs Jan 19 '17 at 12:25

0 Answers0