# Best DB structure - any advice?

**URL:** <https://www.ruby-forum.com/t/best-db-structure-any-advice/149099>\
**Category:** Rails\
**Created:** [September 20, 2008, 11:43am UTC](https://www.ruby-forum.com/t/best-db-structure-any-advice/149099 "2008-09-20T11:43:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [September 20, 2008, 11:43am UTC](https://www.ruby-forum.com/t/best-db-structure-any-advice/149099/1 "2008-09-20T11:43:53Z")

</div>

Hi, I have a basic question about how to setup my models and DB  
structure.

I will have an app that allow users to upload pictures. Pictures are  
related to cities. Users can upload pictures for many cities.

The visitors can view the pictures based on the city they are visiting.  
So when they do a search obviously the search scope on the DB should be  
at city level.

I might end up with many many records and my questions are targeting DB  
efficiency.

1- Should I have a Pictures table that has a City column on it?  
2- Should I have a City table that has a Pictures column on it?

What users will search and view are pictures not cities so I’m not sure  
what will be best if amount of records would be high.

I guess it would be good to use some indexing on Cities also (?)…

As you can see I’m not experienced with DB, any suggestions will be  
appreciated.

Cheers.

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [September 20, 2008, 12:34pm UTC](https://www.ruby-forum.com/t/best-db-structure-any-advice/149099/2 "2008-09-20T12:34:43Z")

</div>

Since a city has\_many pictures this tell you that the pictures table  
has a city\_id foreign key in it.

There isn’t a nice way to do it the other way around.

On Sat, Sep 20, 2008 at 5:43 PM, Pod C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> As you can see I’m not experienced with DB, any suggestions will be  
> appreciated.
> 
> ## Cheers.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ramon T.
