简体   繁体   English

如何组织地理空间的模型类和相关的数据库数据?

[英]How to organize model classes and related database data for geographical spaces?

I am using Ruby on Rails v3.2.2 and MySQL. 我正在使用Ruby on Rails v3.2.2和MySQL。 I would like to "abstract" and "handle" geographical spaces in a balanced way, but I am in trouble when I have to "invent" the overall structure. 我想平衡地“抽象”和“处理” 地理空间,但是当我不得不“发明”整体结构时,我会遇到麻烦。 So... 所以...

How to organize model classes and related database data for geographical spaces? 如何组织地理空间的模型类和相关的数据库数据? That is, for example, which "type" of classes should I implement - should I use something like RoR Single Table Inheritance or Polymorphic classes? 也就是说,例如,我应该实现哪种“类型”的类-是否应该使用RoR单表继承或多态类之类的东西? - ? -? and, given the mentioned model class (or model classes), which table columns should I add to my database and how should those be populated in order to be retrievable (reasons for this are that I am thinking to implement a search form in order to find records in an user friendly way, perhaps with a "autocompletable name" input field)? 并给出给定的模型类(或多个模型类),我应该将哪些表列添加到数据库中,以及应如何填充这些表列以便进行检索(这样做的原因是我正在考虑实施搜索表单,以便以用户友好的方式查找记录,也许使用“自动填充名称”输入字段)?


Note : At this time, I am planning to "organize" a geographical space in ("nested" spaces) continents > countries > regions > cities > addresses . 注意 :目前,我正计划在(“嵌套”空间) continents > countries > regions > cities > addresses “组织”一个地理空间。 However, since retrievability for search form use cases, I am wondering to create one only database table in order to handle those space objects. 但是,由于搜索表单用例的可检索性,我想创建一个唯一的数据库表来处理这些空间对象。

It think that using belongs_to and has_many would be friendly enough, even for autocompletes and something else. 它认为,即使对于自动完成和其他操作,使用belongs_to和has_many也足够友好。

class Continent < ActiveRecord::Base
    has_many :countries
end 

class Country < ActiveRecord::Base
    belongs_to :continent
    has_many :regions
end

class Region < ActiveRecord::Base
    belongs_to :country
    has_many :cities
end

Something like that. 这样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM