<?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"
	>
<channel>
	<title>Comments on: Convert has_and_belongs_to_many to a has_many :through association</title>
	<atom:link href="http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/</link>
	<description>A technical blog</description>
	<pubDate>Fri, 28 Nov 2008 15:27:54 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: adam smith</title>
		<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-170</link>
		<dc:creator>adam smith</dc:creator>
		<pubDate>Fri, 11 Apr 2008 00:25:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-170</guid>
		<description>Here is the follow-up I promised:
  http://www.stonemind.net/blog/2008/04/10/a-potential-confusion-when-converting-habtm-relationships-to-has_many-through/</description>
		<content:encoded><![CDATA[<p>Here is the follow-up I promised:<br />
  <a href="http://www.stonemind.net/blog/2008/04/10/a-potential-confusion-when-converting-habtm-relationships-to-has_many-through/" rel="nofollow">http://www.stonemind.net/blog/2008/04/10/a-potential-confusion-when-converting-habtm-relationships-to-has_many-through/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam smith</title>
		<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-166</link>
		<dc:creator>adam smith</dc:creator>
		<pubDate>Wed, 09 Apr 2008 18:01:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-166</guid>
		<description>It looks like portions of the code got stripped out of the previous comment I made. I may write a small blog post of my own about this, and if so, I'll link back to here.</description>
		<content:encoded><![CDATA[<p>It looks like portions of the code got stripped out of the previous comment I made. I may write a small blog post of my own about this, and if so, I&#8217;ll link back to here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam smith</title>
		<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-165</link>
		<dc:creator>adam smith</dc:creator>
		<pubDate>Wed, 09 Apr 2008 17:12:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-165</guid>
		<description>Guys, 

I have tripped over this myself, and I think I have a tenuous grasp on what's going on that may help. I think the original example above would work like this:

class Soda ; :distributor_sodas
end
 
class Distributor  :distributor_sodas
end
 
class DistributorSoda &#60; ActiveRecord::Base
  belongs_to :soda
  belongs_to :distributor
end


First, the class name: DistributorSoda is always singular. The part I find confusing is that you (might) expect the underlying join table, and therefore the name used for the has_many declaration to be "distributors_sodas", as it would in a HABTM relationship, but instead its "distributor_sodas". In other words, its treated as one word pluralized instead of two words split by the underscore, with each pluralized. This makes sense when you consider that many join tables that are full fledged models go by a better name, like "store" in your example, or "membership" to give another popular example. I think this also explains why specifying :class_name and :foreign_key will also work; its not helping Rails figure out the proper pluralizatio so much as it is bypassing the whole pluralization issue by naming the join table/class/foreign keys explicitly.</description>
		<content:encoded><![CDATA[<p>Guys, </p>
<p>I have tripped over this myself, and I think I have a tenuous grasp on what&#8217;s going on that may help. I think the original example above would work like this:</p>
<p>class Soda ; :distributor_sodas<br />
end</p>
<p>class Distributor  :distributor_sodas<br />
end</p>
<p>class DistributorSoda &lt; ActiveRecord::Base<br />
  belongs_to :soda<br />
  belongs_to :distributor<br />
end</p>
<p>First, the class name: DistributorSoda is always singular. The part I find confusing is that you (might) expect the underlying join table, and therefore the name used for the has_many declaration to be &#8220;distributors_sodas&#8221;, as it would in a HABTM relationship, but instead its &#8220;distributor_sodas&#8221;. In other words, its treated as one word pluralized instead of two words split by the underscore, with each pluralized. This makes sense when you consider that many join tables that are full fledged models go by a better name, like &#8220;store&#8221; in your example, or &#8220;membership&#8221; to give another popular example. I think this also explains why specifying :class_name and :foreign_key will also work; its not helping Rails figure out the proper pluralizatio so much as it is bypassing the whole pluralization issue by naming the join table/class/foreign keys explicitly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-133</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Tue, 22 Jan 2008 12:46:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-133</guid>
		<description>I just figured it out.  You have to specify :class_name, and :foreign_key on the join :belongs_to join model, even when the naming seems "inflectable"(is that a word?).</description>
		<content:encoded><![CDATA[<p>I just figured it out.  You have to specify :class_name, and :foreign_key on the join :belongs_to join model, even when the naming seems &#8220;inflectable&#8221;(is that a word?).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: solipsistic</title>
		<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-10</link>
		<dc:creator>solipsistic</dc:creator>
		<pubDate>Thu, 18 Oct 2007 03:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-10</guid>
		<description>Glad to hear the post was helpful.</description>
		<content:encoded><![CDATA[<p>Glad to hear the post was helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-9</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Wed, 17 Oct 2007 19:50:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.layer2.org/2007/10/10/convert-has_and_belongs_to_many-to-a-has_many-through-association/#comment-9</guid>
		<description>I had been searching for this for 2 days.  I kept getting the "naming bug", uninitialized error on the join table.  Thanks so much for posting. I did the rename, and was all set afterwards.</description>
		<content:encoded><![CDATA[<p>I had been searching for this for 2 days.  I kept getting the &#8220;naming bug&#8221;, uninitialized error on the join table.  Thanks so much for posting. I did the rename, and was all set afterwards.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 3.010 seconds -->
<!-- Cached page served by WP-Cache -->
