Hi!
I am very new to Ruby on Rails and have thus far developed web applications in PHP. I have a problem applying what I have learned about has_one relations to an existing database. The database looks as follows
Table: people id first_name last_name citizenship_jn_id home_country_jn_id travel_country_jn_id
Table: countries id country_name_en iso_country_code
The fields citizenship_jn_id, home_country_jn_id and travel_country_jn_id are all foreign keys to countries table. I have tried to model this in the Person class as follows:
class Person < ActiveRecod::Base has_one :citizenship, :class_name => "Country", :foreign_key => "citizenship_jn_id" has_one :home_country, :class_name => "Country", :foreign_key => "home_country_jn_id" has_one :travel_country_jn_id, :class_name => "Country", :foreign_key => "travel_country_jn_id" end
But this is not correct as the wrong SQL is produced. What would be correct to have the right associations in the model?
Thanks for helping a newbe! Christoph