开发者

rails models for address books (company, person, address)

开发者 https://www.devze.com 2023-03-08 09:07 出处:网络
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 q

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_ma开发者_StackOverflowny :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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消