# Is STI the right way here?

**URL:** <https://www.ruby-forum.com/t/is-sti-the-right-way-here/113188>\
**Category:** Rails\
**Created:** [August 28, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/is-sti-the-right-way-here/113188 "2007-08-28T15:12:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jawosis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jawosis](https://www.ruby-forum.com/u/jawosis)\
**Post date:** [August 28, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/is-sti-the-right-way-here/113188/1 "2007-08-28T15:12:18Z")

</div>

I want to store information about links, podcasts, blogs, wikis …

Each item will have a link, user\_id, created\_at, headline,  
description… additional a podcast item will have fields like  
filetype\_id, duration, mb…, blogs will have a additional field  
like audience…

So my intention is to make a big table with the type field and use  
STI.

Is this the recommended way to store such data or is there a more  
elegant way to solve this?

Thanx

---

<div class="post-metadata">

**Author:** ![jawosis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jawosis](https://www.ruby-forum.com/u/jawosis)\
**Post date:** [August 28, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/is-sti-the-right-way-here/113188/2 "2007-08-28T17:27:49Z")

</div>

why not a polimorphic association?

---

<div class="post-metadata">

**Author:** ![jawosis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jawosis](https://www.ruby-forum.com/u/jawosis)\
**Post date:** [August 28, 2007, 9:03pm UTC](https://www.ruby-forum.com/t/is-sti-the-right-way-here/113188/3 "2007-08-28T21:03:47Z")

</div>

Jochen K. wrote:

> I want to store information about links, podcasts, blogs, wikis …
> 
> Each item will have a link, user\_id, created\_at, headline,  
> description… additional a podcast item will have fields like  
> filetype\_id, duration, mb…, blogs will have a additional field  
> like audience…
> 
> So my intention is to make a big table with the type field and use  
> STI.
> 
> Is this the recommended way to store such data or is there a more  
> elegant way to solve this?

If you can manage to fairly narrowly define which columns you’ll need up  
front then I do think that STI would be the best option here. After all,  
it’s all content plus a couple of extras here and there.

An important operative word in polymorphic associations [1] is  
“associations”. You could model it such that you have a generalized and  
polymorphic association called something like “content”, but when you  
look at it from a functional perspective it really isn’t that much of an  
association at all – it’s contained within the same object. The point  
I’m trying to make here is that I think that using polymorphic  
associations would be a bit of a stretch to make it happen.

So in all: STI is a safe bet and seems fit for use in this case.

[1]  
[http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations](http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations)

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.

---

<div class="post-metadata">

**Author:** ![jawosis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jawosis](https://www.ruby-forum.com/u/jawosis)\
**Post date:** [August 28, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/is-sti-the-right-way-here/113188/4 "2007-08-28T18:12:47Z")

</div>

Raffaele Tesi schrieb:

> why not a polimorphic association?

?? Never heard of this…

–  
Jochen K.  
[railswerk.de](http://railswerk.de), [gissmoh.de](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)
