Table: Raw_Data
Fields: id
name
Table: Actual_Data
Fields: id
raw_data_id
name
A use can either add data manually to Actual_Data (in which case it’s raw_data_id is NULL) or they can select a Raw_Data to insert into Actual_Data (in which case it’s raw_data_id is set).
Is the following relationships correct in this case?
For Raw_Data:
-none-
For Actual_Data:
has_one :raw_data
You are right the relationship should be the same as you said,
As per the rails convention, the foreign key should belongs to the table which has belongs_to association, so here actual_data_id should be in raw_datas table.
Edit:
We don’t need raw_data_id in actual_datas table.