The problem is the following:
I have 3 tables: Companies, Bundles, Documents, with foreign key relationships described in the folling diagrams.
I don’t want two documents belonging to the same company to have the same reference. I envision two solutions:
- Use a matrialized view with the company_id column of bundles and the reference column of document to create a unique index.
- Replicate the company_id column in the documents table, the downside being that i open a way for data inconsistency
Is there any cannonical solution for this problem ?