I have 2 tables scenarios and rental_details.
The relationships are:
- rental_details belongs_to scenarios
- scenarios has_one rental_detail
In the rental_details table I have the scenario_id as a column (note this is as data type INTEGER and not FOREIGN_KEY).
If I run the following in rails console:
rental_details_1 = RentalDetail.find(123)
rental_details_1.id
=> 123
rental_details.scenario.id
=> 22 #i.e. this is linked to scenario with id = 22
However, if I do the following:
scenario_1 = Scenario.find(22)
scenario_1.id
=> 22
scenario_1.rental_details.id
I receive the following error:
NoMethodError: undefined method `rental_details' for
Did you mean? rental_detail rental_detail=
If I change it to scenario_1.rental_details.id
I still receive an error.
If I have a one-to-one relationship such as this, can I not access the rental_details
table from the scenario object? I thought that the foreign key is in the "belongs_to" table I can automatically call its contents from the "has_one" table's object.
(Sorry, I'm new to coding so my terminology is most probably wrong at points).