Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I design a Localised Content table that can join to a number of different tables (the relationship needs to be generic...)
    primarykey
    data
    text
    <p>I know that this isn't exactly normalised, but bringing all of the localised data throughout my application into just a few tables will help me out a lot.</p> <p>I have to be able to link some generic table to a LocalisedContent table which will contain different rows for each of the localised key-value pairs of the generic table joined to it... I guess you could say that it will be a one-to-many relationship.</p> <p>The problem I've found is that I am not sure how to best model this... I can think of two ways and I am not sure which one is best:</p> <p>My first option is:</p> <pre><code>AnExampleOfAGenericTable ------------ AnExampleOfAGenericTableID ...other non-localised data... AnotherGenericTable ------------ AnotherGenericTableID ...other non-localised data... LocalisedContent ---------------- LocalisedContentID genericTablePKName GenericTableID LanguageID field content </code></pre> <p>In the above it would be possible to get out localised content for a generic table with an SQL query like:</p> <pre><code> SELECT AnExampleOfAGenericTableID, field, content FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent ON AnExampleOfAGenericTable.AnExampleOfAGenericTableID = LocalisedContent.GenericTableID WHERE genericTablePKName = 'AnExampleOfAGenericTableID' </code></pre> <p>Or:</p> <pre><code> SELECT AnotherGenericTableID, field, content FROM AnotherGenericTable LEFT JOIN LocalisedContent ON AnotherGenericTable.AnotherGenericTableID = LocalisedContent.GenericTableID WHERE genericTablePKName = 'AnotherGenericTableID' </code></pre> <p>The second option seems to be, something like:</p> <pre><code>AnExampleOfAGenericTable ------------ AnExampleOfAGenericTableID ...other non-localised data... localisedGroupID AnotherGenericTable ------------ AnotherGenericTableID ...other non-localised data... localisedGroupID LocalisedContent ---------------- LocalisedContentID localisedGroupID LanguageID field content </code></pre> <p>And then I could use an SQL query like:</p> <pre><code> SELECT AnExampleOfAGenericTableID, field, content FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent ON AnExampleOfAGenericTable.localisedGroupID = LocalisedContent.localisedGroupID; </code></pre> <p>Or:</p> <pre><code> SELECT AnotherGenericTableID, field, content FROM AnotherGenericTable LEFT JOIN LocalisedContent ON AnotherGenericTable.localisedGroupID = LocalisedContent.localisedGroupID; </code></pre> <p>The second option seems more concise to me, but it does require me to join two FKs which seems a little strange. It also requires a lot of extra 'localisedGroupID' columns.</p> <p>Ultimately both of the examples I've given may be wrong and I don't have the expertise to know the best solution to this. (Before you point out that this isn't fully normalised, I've already said I don't want hundreds of different localised data tables for each of my tables... I do want some amount of centralisation to the localisation even if it will lose me a little referential integrity.)</p> <p>Ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload