<?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: Better in-memory associations with :inverse_of</title>
	<atom:link href="http://mediumexposure.com/better-memory-associations-inverseof/feed/" rel="self" type="application/rss+xml" />
	<link>http://mediumexposure.com/better-memory-associations-inverseof/</link>
	<description>by Maxim Chernyak</description>
	<lastBuildDate>Thu, 15 Jul 2010 14:57:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: hakunin</title>
		<link>http://mediumexposure.com/better-memory-associations-inverseof/comment-page-1/#comment-3284</link>
		<dc:creator>hakunin</dc:creator>
		<pubDate>Sat, 12 Jun 2010 21:49:29 +0000</pubDate>
		<guid isPermaLink="false">#comment-3284</guid>
		<description>&lt;p&gt;Currently all relationship are one-way. A practical explanation would be that if you have:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code lang=&quot;ruby&quot;&gt;
class Horse
  belongs_to :rider
end

class Rider
  has_many :horses
end

# controller
@riders = Rider.all(:include =&gt; :horses)
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;You will end up eager-loading both riders and horses, that&#039;s great. So &lt;code lang=&quot;ruby&quot; inline=&quot;true&quot;&gt;@riders.first.horse&lt;/code&gt; will not run any extra SQL queries. However, &lt;code lang=&quot;ruby&quot; inline=&quot;true&quot;&gt;@riders.first.horse.rider&lt;/code&gt; &lt;strong&gt;will&lt;/strong&gt; run an additional query to fetch the horse&#039;s rider. Because Rails won&#039;t know that they should be the same object. The comprehensive solution would be an identity map, but this commit was a start in the right direction.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Currently all relationship are one-way. A practical explanation would be that if you have:</p>

<p><pre>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Horse<br />
&nbsp; belongs_to <span style="color:#ff3333; font-weight:bold;">:rider</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> Rider<br />
&nbsp; has_many <span style="color:#ff3333; font-weight:bold;">:horses</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;"># controller</span><br />
<span style="color:#0066ff; font-weight:bold;">@riders</span> = Rider.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:horses</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></div>

</pre></p>

<p>You will end up eager-loading both riders and horses, that&#8217;s great. So <code class="codecolorer ruby default"><span class="ruby"><span style="color:#0066ff; font-weight:bold;">@riders</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">horse</span></span></code> will not run any extra SQL queries. However, <code class="codecolorer ruby default"><span class="ruby"><span style="color:#0066ff; font-weight:bold;">@riders</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">horse</span>.<span style="color:#9900CC;">rider</span></span></code> <strong>will</strong> run an additional query to fetch the horse&#8217;s rider. Because Rails won&#8217;t know that they should be the same object. The comprehensive solution would be an identity map, but this commit was a start in the right direction.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Clay Shentrup</title>
		<link>http://mediumexposure.com/better-memory-associations-inverseof/comment-page-1/#comment-3283</link>
		<dc:creator>Clay Shentrup</dc:creator>
		<pubDate>Sat, 12 Jun 2010 21:40:17 +0000</pubDate>
		<guid isPermaLink="false">#comment-3283</guid>
		<description>&lt;p&gt;Can you explain how inverse_of is in any way necessary? The relationships are already described via has_one and belongs_to.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Can you explain how inverse_of is in any way necessary? The relationships are already described via has_one and belongs_to.</p>]]></content:encoded>
	</item>
</channel>
</rss>
