This question should be rather easy, but being fairly new to RoR I''m not sure of the best way to proceed... I have 2 models: City and Location.... Both model belong to the Country model... (So basically a Country has many cities and many locations) Now the tricky part is that... a city can also have Locations... From there, I''m not sure where to go... My first idea was to go with the following relationships: ----------------------------- Location: belongs_to :city belongs_to :country City: belongs_to :country has_many :locations Country: has_many :cities has_many :location ----------------------------- However, I realized that this meant Locations will have both a city_id and a country_id field...in some case, the country_id would be empty, in other cases, the city_id would be empty (depending if the Locations belongs to a city or a country)... Would this work? Somehow this doesn''t sound right? I read a bit on polymorphic association... could this be a better idea for what I''m trying to do? Any help would be appreciated! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MrBanabas-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Nov-30 09:08 UTC
Re: Basic relationship question
Hi, I m not quite sure why you do nt describe the relation like that Country 1 n City 1 n Location which would mean that every Location has a City... If you would like to divide between Locations being in a city rather than being in a village you could add a type filed to the city table... -- Volker --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---