rails models for address books (company, person, address)
Asked Answered
G

1

0

I want to create address-book-like set of models to represent company, person, location, etc. This looks like very typical address book, I wonder if somebody did it already with ruby on rails 3. The question appeared not (only) because of my laziness, but also because "best practice" approach is usually well-developed, have fewer pitfalls, etc. Currently I think about following models/fields:

Company:

  • name

  • has_many :persons

  • has_many :locations

  • has_many :urls, :through => :urlcatalog

    the reason to have URL catalog is a possibility to assign notes to URL

Person:

  • name maybe split to first-middle-last

  • phone

  • has_one :location

  • has_many :emails :through => :emailcatalog

    the reason to have email catalog is the same as above: one can assign "private", "office" labels to it. many phones can be organized this way as well.

Location

  • address optional

  • has_one :city

  • has_one :country

    city or country should be present

City

  • name
  • has_one :country

Country

  • name

any comments on this concept, thoughts, working examples, etc are welcome!

Goya answered 26/5, 2011 at 14:27 Comment(0)
A
0

You should look up polymorphic associations. This means your location will be better organized and it will be easier to get parent etc...

Good example over at RailsWiki

Ashton answered 26/5, 2011 at 14:52 Comment(1)
thanks, in the real application I'll use polymorphic a lot. currently I'm more interested in the general design of such a set of models...Goya

© 2022 - 2024 — McMap. All rights reserved.