First, I'll address concerns about duplicates:
- How to query a parent table and inherited child table together in one query
- This question is similar but it doesn't provide a concrete example
- How can you represent inheritance in a database? suggests "Class Table Inheritance", which is the pattern I'm using, but does not explain how to query it effectively.
Here's a example of the problem I'm facing:
table Document {
id: Id
name: string
type: ??
}
table FooDoc {
id: Id
// Foreign key to Document
docId: Id
qux: string
}
table BarDoc {
id: Id
// Foreign key to document
docId: Id
baz: number
}
Ideally, I'd like to make it so that in 1 query, I can
- grab a document based on its id
- grab the relevant data from the correct child table
Is this possible?