snippetMinor
How to design database for polymorphic relationships
Viewed 0 times
polymorphicdesigndatabaseforhowrelationships
Problem
I have the following scenerio:
How can a model be made without any repetition, and which correctly addresses the polymorphic nature of attributes?
- There are some categories
- Each category has attributes
- An attribute could be of free text or collection of options
- There is a product which is assigned to category which needs to store values/options of attributes
How can a model be made without any repetition, and which correctly addresses the polymorphic nature of attributes?
Solution
I would design a meta-data/value based model, as:
Or, where formality is enforced,
Being
For instance, the hypothetical meta-attribute length, physically stored with
(of course,
Or, where formality is enforced,
Being
AttributeCode and ValueCode unique, textual, human-readable identifiers, alongside the corresponding AttributeId and ValueId.For instance, the hypothetical meta-attribute length, physically stored with
AttributeId = 1, would (should!) be referenced in specific queries as AttributeCode = 'LENGTH'.(of course,
AttributeCode and ValueCode could compose the PKs... but I personally prefer PKs columns to be integer-only)Context
StackExchange Database Administrators Q#50943, answer score: 2
Revisions (0)
No revisions yet.