public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Contacts now include only active users
This was much easier than expected.  The trick was running
Person.find(:first).contacts
and looking in the development log to find the SQL query for the
has_many :contacts, :through => :connections
call.
Michael Hartl (author)
Thu May 08 11:15:29 -0700 2008
commit  553fb9109f673dd90e2c68ea82bff77f1d703629
tree    c397bbc3c393d2b7dcecbf3aa1bf6df467bf6850
parent  ecb54f90dd7778d814c2bd09859d32618d349b19
...
49
50
51
 
 
52
53
 
 
54
55
56
...
88
89
90
 
 
 
 
 
 
 
 
 
 
91
92
93
...
49
50
51
52
53
54
 
55
56
57
58
59
...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
0
@@ -49,8 +49,11 @@
0
   has_many :comments, :as => :commentable, :order => 'created_at DESC',
0
                       :limit => NUM_WALL_COMMENTS
0
   has_many :connections
0
+
0
+
0
   has_many :contacts, :through => :connections,
0
- :conditions => "status = #{Connection::ACCEPTED}",
0
+ :conditions => [%(status = #{Connection::ACCEPTED} AND
0
+ deactivated = ?), false],
0
                       :order => 'people.created_at DESC'
0
   has_many :photos, :dependent => :destroy, :order => 'created_at'
0
   has_many :requested_contacts, :through => :connections,
0
@@ -88,6 +91,16 @@
0
   after_update :log_activity_description_changed
0
 
0
   ## Class methods
0
+# SELECT people.* FROM people INNER JOIN connections ON people.id =
0
+# connections.contact_id WHERE ((connections.person_id = 1) AND ((status = 0)))
0
+# ORDER BY people.created_at DESC
0
+# def contacts
0
+# find(:all,
0
+# :joins => "INNER JOIN people p ON activities.person_id = p.id",
0
+# :conditions => ["p.deactivated = ?", false],
0
+# :order => 'activities.created_at DESC',
0
+# :limit => GLOBAL_FEED_SIZE)
0
+# end
0
 
0
   class << self
0
 
...
63
64
65
66
67
68
69
...
86
87
88
 
 
 
 
 
 
 
 
89
90
91
...
63
64
65
 
66
67
68
...
85
86
87
88
89
90
91
92
93
94
95
96
97
98
0
@@ -63,7 +63,6 @@
0
   end
0
   
0
   describe "contact associations" do
0
-
0
     it "should have associated photos" do
0
       @person.photos.should_not be_nil
0
     end
0
@@ -86,6 +85,14 @@
0
       person = create_person(:save => true)
0
       admin = people(:admin)
0
       person.contacts.first.should == admin
0
+ end
0
+
0
+ it "should not include deactivated users" do
0
+ contact = people(:aaron)
0
+ Connection.connect(@person, contact)
0
+ @person.contacts.should include_the(contact)
0
+ contact.toggle!(:deactivated)
0
+ @person.reload.contacts.should_not include_the(contact)
0
     end
0
     
0
   end

Comments

    No one has commented yet.