Hi Guys, I am a total newbie to rails - so please go easy :) So I have 2 models Country and City - the Country Model will have a ''name'' and a ''code'' field (so a record would be ID name code 1 United Kingdom UK Then my City table would look something like ID country_code city_code name 2 UK LON London So I guess the question is can you use has_many :city which would form the relationship based on the char code rather than a ID? Regards -- Posted via http://www.ruby-forum.com/.
On Aug 10, 1:35 pm, Pete Moran <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi Guys, > > I am a total newbie to rails - so please go easy :) > > So I have 2 models Country and City - the Country Model will have a > ''name'' and a ''code'' field (so a record would be > > ID name code > 1 United Kingdom UK > > Then my City table would look something like > > ID country_code city_code name > 2 UK LON London > > So I guess the question is can you use has_many :city which would form > the relationship based on the char code rather than a ID? >has_many does have a primary_key option for this sort of thing. I would more commonly have a country_id column on cities rather than a country_code column Fred> Regards > -- > Posted viahttp://www.ruby-forum.com/.
Pete Moran wrote:> So I have 2 models Country and City - the Country Model will have a > ''name'' and a ''code'' field (so a record would be > > ID name code > 1 United Kingdom UK > > Then my City table would look something like > > ID country_code city_code name > 2 UK LON LondonCountry ID name code 1 United Kingdom UK City ID country_id city_code name 2 1 LON London Country has_many :cities City belongs_to :country -- Posted via http://www.ruby-forum.com/.