# Tables with only an id

**URL:** <https://www.ruby-forum.com/t/tables-with-only-an-id/92614>\
**Category:** Rails\
**Created:** [April 21, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/tables-with-only-an-id/92614 "2007-04-21T16:42:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 21, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/tables-with-only-an-id/92614/1 "2007-04-21T16:42:19Z")

</div>

Hello,  
I have several tables in my design which have nothing but an id, and I  
can’t  
help thinking that makes them a little superfluous. I’m keeping track of  
versions on a lot of my models, and so I have a venues table and a  
venue\_revisions table, for example. The venues table has nothing except  
an  
id, because everything about a venue can be changed from one version (or  
revision, as I have called it) to the next. Can anyone see a better way  
of  
organising this, or should I just stop concerning myself with it?  
-Nathan

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 22, 2007, 2:34am UTC](https://www.ruby-forum.com/t/tables-with-only-an-id/92614/2 "2007-04-22T02:34:12Z")

</div>

njmacinnes wrote:

> I have several tables in my design which have nothing but an id, and I  
> can’t  
> help thinking that makes them a little superfluous. I’m keeping track of  
> versions on a lot of my models, and so I have a venues table and a  
> venue\_revisions table, for example. The venues table has nothing except an  
> id, because everything about a venue can be changed from one version (or  
> revision, as I have called it) to the next. Can anyone see a better way of  
> organising this, or should I just stop concerning myself with it?  
> -Nathan

In terms of database theory, is the database “normal”? There must be  
some  
field in the venue\_revision table that is always the same across one set  
of  
venues. The first example that comes to mind is the ‘name’ field.  
Refactor  
to migrate this field to the venue table.

Otherwise, you have a “compilable comment”. Take it out, and use  
.with\_scope  
to limit venue queries by some criteria.

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 22, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/tables-with-only-an-id/92614/3 "2007-04-22T18:45:25Z")

</div>

Thanks for the suggestions, but there is no field which will always stay  
the  
same. If you think about it, the name of a venue can change, a venue can  
move (or it can just be that the people who first added the venue didn’t  
know the postcode or got it wrong, or the postcode changed) and a venue  
can  
change ownership.

I could take it out, then use with\_scope as you suggest, but there’s a  
problem with that too. At the moment, a venue has\_many :events (well  
actually, it has\_many event\_revisions, thus creating the same problem  
again,  
but to make things easier to describe, let’s just stick with events). I  
could make venue\_revisions and events have a many-to-many relationship,  
but  
having a seperate venues table (or at least a venue\_id), ensures that an  
event never has more than one venue, although it be related to more than  
one  
venue\_revision.

What I’d ideally like to do is have rails pretend there’s a venues  
table,  
but without actually having one. So each venue revision has a venue\_id,  
and  
each room has a venue\_id, and these are maintained by rails. It’d also  
mean  
people can visit venue pages with ids in the urls, and the latest  
revision  
will automatically be used. I’m not sure if this is entirely normalised,  
but  
it seems it’d do the job pretty well.

-Nathan
