# Another question about database modelling

**URL:** <https://www.ruby-forum.com/t/another-question-about-database-modelling/152710>\
**Category:** Rails\
**Created:** [November 6, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/another-question-about-database-modelling/152710 "2008-11-06T18:03:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [November 6, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/another-question-about-database-modelling/152710/1 "2008-11-06T18:03:00Z")

</div>

Hello,

thanks for reading! 🙂 Ich will describe my problem with the help of  
an example, I think, that’s the quickiest way to present my thoughts.

Let’s assume, you want to save locations. Locations can be of  
different types: country, federal state, town or even a shop or a  
phone cell. These ways of modelling this came to my mind:

1. Create a table for each type of location, identify the common  
properties and extract these to seperate tables, so that you could end  
up in something like this:

Tables: ‘countries’, ‘federal\_states’, ‘towns’ and as an example for a  
table holding common properties ‘demographic\_information’ which will  
be joined with each of the mentioned tables.

1. Identify location categories, whose members have the same  
properties and add a kind of type column referring to a location type  
table, so:

Tables: ‘cat1\_locations’ with a foreign key to a ‘cat1\_location\_types’  
table.

1. I could imagine to modell this polymorphic, but I’ve got no clear  
idea right now, maybe you have heard more about this and are willing  
to tell me more about this, I would really appreciate this.

Let’s come to my question: Which way would you modell this? What other  
possibilities are there to modell this, maybe a kind of modelling  
pattern? Can you name me criterias on which my decision should be  
based?

Thank you really much!

Best wishes,  
ms

---

<div class="post-metadata">

**Author:** ![msmsms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@msmsms](https://www.ruby-forum.com/u/msmsms)\
**Post date:** [November 7, 2008, 10:10am UTC](https://www.ruby-forum.com/t/another-question-about-database-modelling/152710/2 "2008-11-07T10:10:08Z")

</div>

On 6 Nov, 18:02, ms [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> thanks for reading! 🙂 Ich will describe my problem with the help of  
> an example, I think, that’s the quickiest way to present my thoughts.
> 
> Let’s assume, you want to save locations. Locations can be of  
> different types: country, federal state, town or even a shop or a  
> phone cell. These ways of modelling this came to my mind:

Hi,  
IMHO the best way is Nested Set, you can find a lot of tutorials  
online.  
This approach can represent different administrative organization in  
the same time.

Danilo
