<?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: Modeling bidirectional graph edges in Rails</title>
	<atom:link href="http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/</link>
	<description>Web Freshness</description>
	<lastBuildDate>Mon, 05 Jul 2010 23:44:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Maarten</title>
		<link>http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/comment-page-1/#comment-559</link>
		<dc:creator>Maarten</dc:creator>
		<pubDate>Tue, 29 Dec 2009 08:51:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/?p=96#comment-559</guid>
		<description>Hi

Are you sure your friends association works?

&lt;code lang=&quot;ruby&quot;&gt;has_many :friends, :through =&gt; :befriending_edges, :source =&gt; :user&lt;/code&gt;

The :through just follows the user association on the befriending_edge, pointing back to the user itself, no?</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Are you sure your friends association works?</p>
<p><pre class="ruby">has_many <span class="re3">:friends</span>, <span class="re3">:through</span> <span class="sy0">=&gt;</span> <span class="re3">:befriending_edges</span>, <span class="re3">:source</span> <span class="sy0">=&gt;</span> <span class="re3">:user</span></pre></p>
<p>The :through just follows the user association on the befriending_edge, pointing back to the user itself, no?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: duncanbeevers</title>
		<link>http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/comment-page-1/#comment-529</link>
		<dc:creator>duncanbeevers</dc:creator>
		<pubDate>Mon, 18 May 2009 18:34:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/?p=96#comment-529</guid>
		<description>The proposed table structure looks like this.

&lt;strong&gt;Users&lt;/strong&gt;
id

&lt;strong&gt;Befriendings&lt;/strong&gt;
initiator_id
recipient_id
&lt;em&gt;Unique index on initiator_id, recipient_id&lt;/em&gt;

&lt;strong&gt;BefriendingEdges&lt;/strong&gt;
user_id
befriending_id
&lt;em&gt;Unique index on user_id, befriending_id&lt;/em&gt;

All graph information is accessed through associations on User.  For example, accessing information about the relationship between User 1 and User 2 might look like this.
&lt;code lang=&quot;ruby&quot;&gt;
user1, user2 = User.find(1, 2)
user1.befriendings.find(:first, :conditions =&gt; { :recipient_id =&gt; user2.id })
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>The proposed table structure looks like this.</p>
<p><strong>Users</strong><br />
id</p>
<p><strong>Befriendings</strong><br />
initiator_id<br />
recipient_id<br />
<em>Unique index on initiator_id, recipient_id</em></p>
<p><strong>BefriendingEdges</strong><br />
user_id<br />
befriending_id<br />
<em>Unique index on user_id, befriending_id</em></p>
<p>All graph information is accessed through associations on User.  For example, accessing information about the relationship between User 1 and User 2 might look like this.<br />
<pre class="ruby">user1, user2 = User.<span class="me1">find</span><span class="br0">&#40;</span><span class="nu0">1</span>, <span class="nu0">2</span><span class="br0">&#41;</span>
user1.<span class="me1">befriendings</span>.<span class="me1">find</span><span class="br0">&#40;</span><span class="re3">:first</span>, <span class="re3">:conditions</span> <span class="sy0">=&gt;</span> <span class="br0">&#123;</span> <span class="re3">:recipient_id</span> <span class="sy0">=&gt;</span> user2.<span class="me1">id</span> <span class="br0">&#125;</span><span class="br0">&#41;</span></pre></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/comment-page-1/#comment-528</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Mon, 18 May 2009 18:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/?p=96#comment-528</guid>
		<description>Your modeling is really interesting, but I&#039;m not sure to understand correctly. Could you indicate the different tables involved and the fields in those tables, I&#039;m especially confused about the befriending_edges table. Thanks a lot!</description>
		<content:encoded><![CDATA[<p>Your modeling is really interesting, but I&#8217;m not sure to understand correctly. Could you indicate the different tables involved and the fields in those tables, I&#8217;m especially confused about the befriending_edges table. Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: duncanbeevers</title>
		<link>http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/comment-page-1/#comment-527</link>
		<dc:creator>duncanbeevers</dc:creator>
		<pubDate>Fri, 08 May 2009 04:38:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/?p=96#comment-527</guid>
		<description>I think it&#039;s simplest to think of this solution in terms of the associations on the User model, and the kinds of questions we want to ask about Users.  For example, one question is &quot;Who are my friends?&quot;  Another question is &quot;When did we become friends?&quot;

In a system with strictly bi-directional befriending (if User A is friends with User B then User B is necessarily friends with User A) asking &quot;Who are my friends?&quot; can be an expensive operation for the reasons outlined above.

The BefriendingEdges are never addressed directly.  That is, we never (or rarely) ask the question &quot;What befriendings have I initiated?&quot; or &quot;What befriendings am I a participant in but was not the initiator?&quot;  However, despite the fact that we never ask these questions directly, modeling the graph edges separately allows for faster answers to the other more general questions.

All queries from the User through to either another User or to a Befriending use the BefriendingEdge as a through model.  It&#039;s not a belongs_to going through another belongs_to.  Rather, it&#039;s two has_manys throughs that utilize a common has_many.</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s simplest to think of this solution in terms of the associations on the User model, and the kinds of questions we want to ask about Users.  For example, one question is &#8220;Who are my friends?&#8221;  Another question is &#8220;When did we become friends?&#8221;</p>
<p>In a system with strictly bi-directional befriending (if User A is friends with User B then User B is necessarily friends with User A) asking &#8220;Who are my friends?&#8221; can be an expensive operation for the reasons outlined above.</p>
<p>The BefriendingEdges are never addressed directly.  That is, we never (or rarely) ask the question &#8220;What befriendings have I initiated?&#8221; or &#8220;What befriendings am I a participant in but was not the initiator?&#8221;  However, despite the fact that we never ask these questions directly, modeling the graph edges separately allows for faster answers to the other more general questions.</p>
<p>All queries from the User through to either another User or to a Befriending use the BefriendingEdge as a through model.  It&#8217;s not a belongs_to going through another belongs_to.  Rather, it&#8217;s two has_manys throughs that utilize a common has_many.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cameron</title>
		<link>http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/comment-page-1/#comment-526</link>
		<dc:creator>Cameron</dc:creator>
		<pubDate>Thu, 07 May 2009 11:20:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/?p=96#comment-526</guid>
		<description>So you can have a belongs_to model that goes through another belongs_to model?
I am kinda confused as a new rails guy. Could you explain a bit more about these edges please?</description>
		<content:encoded><![CDATA[<p>So you can have a belongs_to model that goes through another belongs_to model?<br />
I am kinda confused as a new rails guy. Could you explain a bit more about these edges please?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
