0

BACKGROUND: I have City model and I'd like users to be able to select both a Hometown and a Current City from the master list of Cities, so as to be able to call user.hometown and user.currentcities as methods.

QUESTION: What are some approaches for best tackling this scenario?

UPDATE I forgot to mention that City is itself a type of Community (there are other types of communities users can select besides City) - which is why I'm using STI.

neon
  • 2,811
  • 6
  • 30
  • 44

1 Answers1

0

The easiest would be to add hometown_id and currentcity_id as columns on the users table and then give the User model two associations:

belongs_to :hometown, :class_name => 'City'
belongs_to :currentcity, :class_name => 'City'

I don't think you need STI here unless I missed something.

Edit

If City is a sub-class via STI then changing class_name in the examples above to be the class of the base STI class should allow the User associations to link to a community.

patrickmcgraw
  • 2,465
  • 14
  • 8
  • I forgot to mention that City is itself a type of Community (there are other types of communities users can select besides City) - which is why I'm using STI. This is a good starting point for me though! – neon Jul 24 '14 at 00:11