Search code examples
rubydatabasesequelpadrino

Best strategy to store multiple translation records in DB


Assuming few fields (say under 6/7) whats the best strategy to store multiple language translation for DB records, consider the following two cases.

Say we have a table with the following fields:

id, title, description

Every record will have an English and Arabic translation. So, consider the two cases I am using:

Case 1:

Add two more fields: title_ar and description_ar.

Case 2:

Add a field: language and make a composite key out of id and language.

Considering the complexity of dealing with the composite key (I am using Sequel ORM), I am rethinking whether going with the first approach might be better. Please explain if there are any major drawbacks or advantages for either of the approaches.


Solution

  • Translator DB Model

    This approach would scale even if it's planned to accommodate multiple language translations.

    Associations

    Sentence has many language translations
    Translation belongs to Sentence


    Drawbacks of the first approach,

    If we were to extend the application to multiple languages then we have to add the corresponding fields to the table

    Advantage of the second approach,

    As we have id reference specific to the sentence, we can fetch the corresponding description in desired language quicker.