Question: Table referenced by many tables

Hi my name is Nathan,

I am building a website using Ruby on Rails and a MySQL database. The
premise is that every news item and piece of article content or a
download etc each has it’s own forum.

Currently I have it set up so that my News, Content, and Downloads
tables each have a discussion_id column. The Discussion table is then
referenced by Forums, Forums are referenced by Threads and Threads are
referenced by Posts.

This way any piece of content on my website can have it’s own set of
forums.

The problem is that Discussion has no way of knowing which table is
referencing it. If I am viewing a thread on my website, I want to be
able to have links that take you back to the article you were viewing or
the main page that article is stored on such as the news page, but I
can’t do that without knowing what is referencing the Discussion. Be it
News or Articles or Downloads or whatever.

How can I use single-table inheritance with a ‘type’ column in my Forums
table, to eliminate the Discussions table all together? This way several
forums could reference the news item or a download directly.

Thank you for your help, I am catching on quickly to Ruby on Rails
symantics but this single-table inheritance stuff is crazy talk and I
don’t know how to make it work.

I’ve also taken the liberty of making a picture of what I want:

Sorry I can’t seem to post images direct to Ruby Forum.

Nathan V. wrote:

I’ve also taken the liberty of making a picture of what I want:

Sorry I can’t seem to post images direct to Ruby Forum.

http://img69.imageshack.us/my.php?image=myautograph9fj.gif

Hi, I didn’t know much and even made a mistake in my thread title, this
is actually one table referencing many tables. I figured out the
solution so anybody wanting to know I’ve posted to the wiki.

http://wiki.rubyonrails.com/rails/pages/SimplePolymorphicAssociation