<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Rails/ActiveRecord: belongs_to :polymorphic =&gt; true</title>
	<atom:link href="http://www.jtanium.com/2009/10/22/railsactiverecord-belongs_to-polymorphic-true/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jtanium.com/2009/10/22/railsactiverecord-belongs_to-polymorphic-true/</link>
	<description>I jot things down, in hopes of finding them later...</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:07:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Andy</title>
		<link>http://www.jtanium.com/2009/10/22/railsactiverecord-belongs_to-polymorphic-true/comment-page-1/#comment-4660</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Tue, 15 Nov 2011 14:47:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.jtanium.com/?p=161#comment-4660</guid>
		<description>Very good and useful. Thanks</description>
		<content:encoded><![CDATA[<p>Very good and useful. Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jtanium</title>
		<link>http://www.jtanium.com/2009/10/22/railsactiverecord-belongs_to-polymorphic-true/comment-page-1/#comment-421</link>
		<dc:creator>jtanium</dc:creator>
		<pubDate>Mon, 07 Dec 2009 01:39:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.jtanium.com/?p=161#comment-421</guid>
		<description>Yes, in this respect has_one and has_many function similarly.  I was just trying to come up with an example to demonstrate it&#039;s use.

Now, as far as belongs_to :book, belongs_to :album, and belongs_to :movie, sure you could do that, but then when you try to use the item associated with the artwork you&#039;re going to have to do something ugly like:

if artwork.book
# do book stuff here
elsif artwork.movie
# do movie stuff here
elsif artwork.album
# do album stuff here
else
# uh oh!
end

This makes your code brittle, not to mention tedious. This polymorphic association provides you with a layer of indirection (a.k.a. abstraction) that would protect you from something such as adding another &quot;belongs_to :&quot; (e.g. :video_game).</description>
		<content:encoded><![CDATA[<p>Yes, in this respect has_one and has_many function similarly.  I was just trying to come up with an example to demonstrate it&#8217;s use.</p>
<p>Now, as far as belongs_to :book, belongs_to :album, and belongs_to :movie, sure you could do that, but then when you try to use the item associated with the artwork you&#8217;re going to have to do something ugly like:</p>
<p>if artwork.book<br />
# do book stuff here<br />
elsif artwork.movie<br />
# do movie stuff here<br />
elsif artwork.album<br />
# do album stuff here<br />
else<br />
# uh oh!<br />
end</p>
<p>This makes your code brittle, not to mention tedious. This polymorphic association provides you with a layer of indirection (a.k.a. abstraction) that would protect you from something such as adding another &#8220;belongs_to :&#8221; (e.g. :video_game).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: about2flip</title>
		<link>http://www.jtanium.com/2009/10/22/railsactiverecord-belongs_to-polymorphic-true/comment-page-1/#comment-420</link>
		<dc:creator>about2flip</dc:creator>
		<pubDate>Sun, 06 Dec 2009 18:14:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.jtanium.com/?p=161#comment-420</guid>
		<description>Couldn&#039;t book, album and movie has_many instead of has_one?
Also, why couldn&#039;t Artwork model belongs_to :book, belongs_to :album, belongs_to :movie

Thanks</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t book, album and movie has_many instead of has_one?<br />
Also, why couldn&#8217;t Artwork model belongs_to :book, belongs_to :album, belongs_to :movie</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>

