<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>blog.dnite.org - has_many_friends released! Comments</title>
  <id>tag:blog.dnite.org,2008:/2007/3/14/has_many_friends-released/comments</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
  <updated>2007-09-30T18:23:28Z</updated>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>lukey</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:1115</id>
    <published>2007-09-30T18:23:28Z</published>
    <updated>2007-09-30T18:23:28Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by lukey</title>
<content type="html">&lt;p&gt;Hi Steve,&lt;/p&gt;


	&lt;p&gt;I got it, just had to do this sensible thing in my method:
:order =&amp;gt; &#8220;accepted_at desc&#8221;,
:limit =&amp;gt; &#8220;3&#8221;) + @user.friends_by_me.find(:all,
:order =&amp;gt; &#8220;accepted_at desc&#8221;,
:limit =&amp;gt; &#8220;3&#8221;)&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;@friends = @user.friends_for_me.find(:all,&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;and vola, it works amazingly&#8230;Thanks for this amazing plugin&#8230;&lt;/p&gt;


	&lt;p&gt;Cheers&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>lukey</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:1112</id>
    <published>2007-09-30T14:14:09Z</published>
    <updated>2007-09-30T14:14:09Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by lukey</title>
<content type="html">&lt;p&gt;Hi Steve,&lt;/p&gt;


	&lt;p&gt;thanks for the reply and apologies for the delayed reply, well here&#8217;s the full error:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;ArgumentError in User profilesController#home&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;wrong number of arguments (2 for 1)&lt;/p&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;RAILS&lt;/span&gt;_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace&lt;/p&gt;


&lt;h1&gt;{RAILS_ROOT}/app/controllers/user_profiles_controller.rb:51:in `find&#8217;&lt;/h1&gt;

&lt;h1&gt;{RAILS_ROOT}/app/controllers/user_profiles_controller.rb:51:in `home&#8217;&lt;/h1&gt;





	&lt;p&gt;where line number 51 is:
@friends = @user.friends.find(:all,
:order =&amp;gt; &#8220;accepted_at desc&#8221;,
:limit =&amp;gt; &#8220;2&#8221;)&lt;/p&gt;


	&lt;p&gt;in my view am getting the users name, and picture to be displayed, it works pretty well as long as its just @friends = @user.friends&lt;/p&gt;


	&lt;p&gt;here&#8217;s my method in controller:&lt;/p&gt;


	&lt;p&gt;def home
@user = User.find(session[:user_id])
  @users = User.available_users
     @user_pic = UserPic.find(:first, :conditions =&amp;gt; [&#8216;user_id=?&#8217;, current_user]) 
          @friend = current_user
             @friends = @user.friends.find(:all, :order =&amp;gt; &#8220;accepted_at desc&#8221;, :limit =&amp;gt; &#8220;2&#8221;)&lt;/p&gt;


	&lt;p&gt;end&lt;/p&gt;


	&lt;p&gt;Just not able to get this right&#8230;Thanks a lot in advance for your help&#8230;&lt;/p&gt;


	&lt;p&gt;Cheers&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Steve</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:632</id>
    <published>2007-09-04T08:07:05Z</published>
    <updated>2007-09-04T08:07:05Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Steve</title>
<content type="html">&lt;p&gt;@lukey: I&#8217;d love to offer some advise but I&#8217;d need you to post some more information about the error your receiving. Where are you getting the wrong argument error? Maybe posting a small portion of the error your getting? What method does the error happen on?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Lukey</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:609</id>
    <published>2007-09-03T04:51:58Z</published>
    <updated>2007-09-03T04:51:58Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Lukey</title>
<content type="html">&lt;p&gt;Hi Steve,&lt;/p&gt;


	&lt;p&gt;I am using this wonderful plug-in for my development and I have one small query problem that gives me an error, nothing wrong with the plugin but its a custom.  requirement:&lt;/p&gt;


	&lt;p&gt;I need to list user names and pictures of corresponding users and that too by limiting the list to just 5 users.&lt;/p&gt;


	&lt;p&gt;Heres the controller code:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;def mini_friendlist&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;@friend = User.find(session[:user_id])
       @user = User.find(params[:id])
@friends = @user.friends.find(:all,
:limit =&amp;gt; &#8220;5&#8221;)&lt;/p&gt;


	&lt;p&gt;end&lt;/p&gt;


	&lt;p&gt;Here&#8217;s my view code:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;&quot;&gt;&amp;lt;%=image_path url_for( :controller =&gt; &#8220;user_pics&#8221;, :action =&amp;gt; &#8220;show_thumb&#8221;,
:id =&amp;gt; friendship.user_pic ) %&amp;gt;&#8221; /&amp;gt;&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;&amp;lt;%= friendship.name %&amp;gt;&lt;/p&gt;


	&lt;p&gt;When I write this query I get a wrong argument error.&lt;/p&gt;


	&lt;p&gt;Please guide me with this task&#8230; any help is appreciated.&lt;/p&gt;


	&lt;p&gt;Cheers&lt;/p&gt;


	&lt;p&gt;Lukey&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>steve</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:111</id>
    <published>2007-06-09T08:57:50Z</published>
    <updated>2007-06-09T08:57:50Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by steve</title>
<content type="html">&lt;p&gt;I wrote up a &lt;a href=&quot;http://blog.dnite.org/2007/6/8/howto-has_many_friends&quot;&gt;howto&lt;/a&gt; (kinda) so those of you who are having trouble using this plugin can check it out and see if it helps you out any. Enjoy!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>BustyBoots</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:89</id>
    <published>2007-06-01T03:03:07Z</published>
    <updated>2007-06-01T03:03:07Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by BustyBoots</title>
<content type="html">&lt;p&gt;I don’t want to wait till the end of Summer :( , I want it now. Who with me? 
save your time &lt;a href=&quot;http:&quot; /&gt; and join me&lt;/a&gt;. ;)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Jim Morris</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:69</id>
    <published>2007-05-20T04:44:54Z</published>
    <updated>2007-05-20T04:44:54Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Jim Morris</title>
<content type="html">&lt;p&gt;Hi&#8230; I have done something almost identical although not as a plugin. The main differences is I needed the referenced class to be something other than User so any class can have_many_friends so to speak.&lt;/p&gt;


	&lt;p&gt;I also wrote this for the friends function, rather than concatenating two lists, seemed more efficient somehow&#8230;&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;has_many :friends, :class_name =&amp;gt; &quot;Person&quot;, :finder_sql =&amp;gt;
  'SELECT p.* FROM people p, friends f WHERE f.status = 1 AND ( (f.invitee_id = #{id} AND p.id = f.inviter_id) OR (f.inviter_id = #{id} AND p.id = f.invitee_id) )'&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Ignore the minor naming differences.&lt;/p&gt;


	&lt;p&gt;I would also use a sql finder to see if someone is a friend or not rather than loading all my friends into a list and seeing if they are in the list. I believe that maybe more scaleable if someone has a huge number of friends. Also I have the friend_id&#8217;s fks indexed which also will help with performance.&lt;/p&gt;


	&lt;p&gt;Other than minor naming differences it is eerie how similar our two approaches are.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Steve</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:66</id>
    <published>2007-05-16T20:47:32Z</published>
    <updated>2007-05-16T20:47:32Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Steve</title>
<content type="html">&lt;p&gt;I can tell that some people are having problems with this so I&#8217;ll go ahead and make a new post that will teach the basics and maybe give some examples about how I implemented it into my restful apps in the very near future. Thanks for the comments, everyone!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Nick</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:64</id>
    <published>2007-05-16T13:37:59Z</published>
    <updated>2007-05-16T13:37:59Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Nick</title>
<content type="html">&lt;p&gt;Actually, have written a very dirty add_friend method in my user_controller&lt;/p&gt;


	&lt;p&gt;def add_friend
    #dirty code, just to get it working
    @friend = Friendship.new
    @friend.user_id = session&lt;a&gt;:user&lt;/a&gt;
    @friend.friend_id = params[:id]
    @friend.save
  end&lt;/p&gt;


	&lt;p&gt;Then in the view&lt;/p&gt;


	&lt;p&gt;&amp;lt;% @user.pending_friends.each do |u| %&amp;gt;
        &amp;lt;%= u.login %&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Nick</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:63</id>
    <published>2007-05-16T13:01:53Z</published>
    <updated>2007-05-16T13:01:53Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Nick</title>
<content type="html">&lt;p&gt;I&#8217;d second lambo4jos &#8217;s comment, I&#8217;ve been messing around for ages and can&#8217;t get to first base with the controller code&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>lambo4jos</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:62</id>
    <published>2007-05-16T04:12:52Z</published>
    <updated>2007-05-16T04:12:52Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by lambo4jos</title>
<content type="html">&lt;p&gt;This seems like a great plugin.  Do you have any sample controller methods?  Is it possible for you to help me out with this?  I am having a difficult time figuring out the controller parts of rails and this plugin.  Any help would be wonderful.  Thanks in advance.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Chuck</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:57</id>
    <published>2007-05-01T20:32:23Z</published>
    <updated>2007-05-01T20:32:23Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Chuck</title>
<content type="html">&lt;p&gt;Can you give me some pointers on the best way to make this restful again? I was interested in using your restful friends idea, but that seems to not survived the transition to plugin.&lt;/p&gt;


	&lt;p&gt;Chuck&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Chuck</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:56</id>
    <published>2007-05-01T16:42:49Z</published>
    <updated>2007-05-01T16:42:49Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Chuck</title>
<content type="html">&lt;p&gt;Can you give me some pointers on the best way to make this restful again? I was interested in using your restful friends idea, but that seems to not survived the transition to plugin.&lt;/p&gt;


	&lt;p&gt;Chuck&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Steve</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:53</id>
    <published>2007-04-24T15:25:39Z</published>
    <updated>2007-04-24T15:25:39Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Steve</title>
<content type="html">&lt;p&gt;@joe: hm. i never thought about this. The easiest (and somewhat non-normalized) way of doing things would be to just add a &#8216;friendship_type&#8217; column to the friendship model that could hold the type of friend. The cool thing about using a relationship model is that you can add attributes to the friendship. You could also do a whole new model for friendship_type and add a &#8216;has_one friendship_type&#8217; to the friendship model too. Let me know if any of those methods work for ya.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Joe</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:51</id>
    <published>2007-04-24T02:32:29Z</published>
    <updated>2007-04-24T02:32:29Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Joe</title>
<content type="html">&lt;p&gt;Hi Steve,
I really like your plugin it&#8217;s &lt;span class=&quot;caps&quot;&gt;EXACTLY&lt;/span&gt; what I was looking for, Thanks. 
I have one question though&#8230;.Let&#8217;s say I wanted two types of Friends (BestFriend and RegularFriend) associated with the same Friend Class, how could I do this?
I was thinking maybe making a has_one association with a child class called BestFriend and Regularfriend and adding your has_many_friends at that level, but I&#8217;m not sure if that would work.
Please advise if you could,
Thanks again.
Joe&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>rahsun</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:46</id>
    <published>2007-04-12T16:52:40Z</published>
    <updated>2007-04-12T16:52:40Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by rahsun</title>
<content type="html">&lt;p&gt;Ohhhhh &#8211; nice &#8211; can&#8217;t wait to check out!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>David Cancel</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:44</id>
    <published>2007-04-11T19:33:44Z</published>
    <updated>2007-04-11T19:33:44Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by David Cancel</title>
<content type="html">&lt;p&gt;Steve,&lt;/p&gt;


	&lt;p&gt;Just wanted to let you know I posted your plugin to the repository on AgileWebDevelopment.com&lt;/p&gt;


	&lt;p&gt;http://agilewebdevelopment.com/plugins/has_many_friends&lt;/p&gt;


	&lt;p&gt;Cheers,
David&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Steve</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:40</id>
    <published>2007-04-06T08:45:22Z</published>
    <updated>2007-04-06T08:45:22Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Steve</title>
<content type="html">&lt;p&gt;Sorry about that. I decided I didn&#8217;t really need the Trac&#8217;s for the time being. Everything should just link to svn.dnite.org, so I changed the links. They should work now.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://blog.dnite.org/">
    <author>
      <name>Piku</name>
    </author>
    <id>tag:blog.dnite.org,2007-03-14:11:38</id>
    <published>2007-04-05T14:16:11Z</published>
    <updated>2007-04-05T14:16:11Z</updated>
    <category term="My Stuff"/>
    <category term="Ruby on Rails"/>
    <link href="http://blog.dnite.org/2007/3/14/has_many_friends-released" rel="alternate" type="text/html"/>
    <title>Comment on 'has_many_friends released!' by Piku</title>
<content type="html">&lt;p&gt;Thanks for your plugin but the Trac is down now. dev.dnite.org is the same as dnite.org.&lt;/p&gt;</content>  </entry>
</feed>
