How should I define a composite foreign key for domain constraints in the presence of surrogate keys
- by Samuel Danielson
I am writing a new app with Rails so I have an id column on every table. What is the best practice for enforcing domain constraints using foreign keys? I'll outline my thoughts and frustration.
Here's what I would imagine as "The Rails Way". It's what I started with.
Companies:
id: integer, serial
company_code: char, unique, not null
…