开发者

What is a good way to model city, regions and postcodes?

I am thinking about the "best" way to model city, region, postcodes for usage in different countries. (Application should be used in different languages)

My first guess is:

class City {
    String name
    String region
    static hasMany = [postcodes:PostCode]
    static belongsTo = [region:Region]
    static constraints = {
        name size:2..100
        region nullable:true
    }
}

Now the questions are:

  • Can one city belong to more than one r开发者_开发问答egion? (States/Bundesländer/Communities/...)
  • As all of this is final, no new cities, regions or postCodes I thought about not using the database and put it into enums!?
  • As I want to separate data for different countries I have to add this to a city. I took a look at multiTenant-plugin but I am not quite sure if this isn't to much!?

Probably someone has dealt with this before and can share some insights.

Thanks a lot Sebastian


Can one city belong to more than one region? (States/Bundesländer/Communities/...)

That depends on you. You haven't explicitly stated what a region is. A region could be the suburbs of x city or Western Europe depending on how you define it. If a region isn't defined by state boundaries, then it's possible that a city can belong to more than one region. For example, "Paris" could be contained in the "France" region as well as the "Western Europe" region.

A simple solution would be to limit regions to state boundaries, but that might not be a good solution depending on what you need the data for. You could create an array of strings to store your regions, but it's difficult to pick an alternative if you don't say what the data is needed for. Based off of what you've written, I think a separate "String country" would be appropriate since you can then sort by country, and your regions can remain as they are.

As all of this is final, no new cities, regions or postCodes I thought about not using the database and put it into enums!?

You could do that, but it's much easier to manage in a DB.

As I want to separate data for different countries I have to add this to a city. I took a look at multiTenant-plugin but I am not quite sure if this isn't to much!?

I'm haven't used the plugin so I can't help you there, but if you just want to separate data by country, then adding a country field and sorting would be pretty straightforward.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜