In the error / error model, where will the foreign key reside?
I always get stuck on foreign keys, so I have a question about where the foreign key should be in the bug tracking system where the bug has one status at any given time as long as only a small number of statuses exist (Open, Investigation, solutions pending approval). Thus, each status has many errors associated with it. My guess is that the foreign key should be in the Bug table as the status_id column referencing the id column in the status table. Is this a safe assumption?
TABLE:
Bug
id integer
desc string
status_id integer fk
Status
id integer
desc string
RAILS MODEL:
Bug
has_one :status
Status
has_and_belongs_to_many :bugs
Are you correct in your assumption, more importantly, then the relationship (One-Many / One-One / Many-Many) determines which table is the primary key table and which is the foreign key table?
In this case, the state table explicitly contains the primary key of the relationship FK. If it were the other way around, then every status must exist in the Bug table before it can exist in the status table, which is clearly not intended.
a source to share