通讯录的Rails模型(公司,人员,地址) [英] rails models for address books (company, person, address)

查看:111
本文介绍了通讯录的Rails模型(公司,人员,地址)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一组类似于地址簿的模型来表示公司,人员,位置等。这看起来非常典型,我想知道是否有人已经在Ruby 3上做到了这一点。问题似乎不存在(仅)是由于我的懒惰,也是因为最佳实践方法通常很发达,陷阱少等。目前,我正在考虑以下模型/领域:

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:

公司:


  • name

  • has_many:persons

  • has_many:locations

  • has_many:urls,:through =>:urlcatalog

  • name
  • has_many :persons
  • has_many :locations
  • has_many :urls, :through => :urlcatalog

拥有URL目录的原因是可以为URL分配注释

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

人员:


  • 名称​​可能会被拆分为第一中最后一位

  • 电话

  • has_one:location

  • has_many:emails:through =>:emailcatalog

  • 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.

位置


  • 地址可选

  • has_one:city

  • has_one:国家

  • address optional
  • has_one :city
  • has_one :country

应该存在城市或国家

城市


  • 名称

  • has_one:国家

国家/地区


  • 名称

欢迎对此概念,想法,工作示例等发表任何评论!

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...

RailsWiki

这篇关于通讯录的Rails模型(公司,人员,地址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆