I'm designing a document translation DB and struggling to connect the non-generic many-to-many table.
Each document has a title and summary.
Translated Document table:
CREATE table translated_documents (
document_id bigint references documents (id),
source_language_id int not null,
source_title_hash uuid, -- md5 hash cast to uuid
source_summary_hash uuid,
PRIMARY KEY (document_id)
);
CREATE TABLE translations (
content_hash uuid not null, -- holds either source_title_hash or source_summary_hash
translation_language_id int not null,
content_translation text not null,
PRIMARY KEY (content_hash, translation_language_id)
);
An attempt at a many-to-many table, trying to reference the content_hash
column twice.
CREATE TABLE translated_documents_translations (
document_id bigint references translated_documents (document_id),
source_title_hash uuid not null references translations (content_hash),
source_summary_hash uuid not null references translations (content_hash),
PRIMARY KEY (source_title_hash),
CONSTRAINT same_hash_not_allowed CHECK (source_title_hash <> source_summary_hash)
);
My thinking is that documents can be translated into many languages, and translations can work for many documents with the same title or summary. Is there a better way to set this up?
Best Answer
I think unless you have to save space or share a lot of translations you could just do one-to-many mapping
documents
->document_translations
Then you could use external translation memory to help with translations.
If you want to share translations then I don't think you need
translated_documents_translations
as many-to-many table. Just usetranslated_documents
like this:And
JOIN
documents
->documents_translations
->translations