diff --git a/app/models/contact.rb b/app/models/contact.rb index 6482e45a8..4a39d2a90 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -69,10 +69,10 @@ class Contact < ActiveRecord::Base def contacts people = Person.arel_table - incoming_aspects = Aspect.joins(:contacts).where( + incoming_aspects = Aspect.where( :user_id => self.person.owner_id, - :contacts_visible => true, - :contacts => {:person_id => self.user.person.id}).select('aspects.id') + :contacts_visible => true).joins(:contacts).where( + :contacts => {:person_id => self.user.person.id}).select('aspects.id') incoming_aspect_ids = incoming_aspects.map{|a| a.id} similar_contacts = Person.joins(:contacts => :aspect_memberships).where( :aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT people.*') diff --git a/app/models/person.rb b/app/models/person.rb index 416679c80..d8251c964 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -71,7 +71,8 @@ class Person < ActiveRecord::Base # @note user is passed in here defensively scope :all_from_aspects, lambda { |aspect_ids, user| joins(:contacts => :aspect_memberships). - where(:contacts => {:user_id => user.id}, :aspect_memberships => {:aspect_id => aspect_ids}) + where(:contacts => {:user_id => user.id}). + where(:aspect_memberships => {:aspect_id => aspect_ids}) } scope :unique_from_aspects, lambda{ |aspect_ids, user| @@ -81,7 +82,7 @@ class Person < ActiveRecord::Base #not defensive scope :in_aspects, lambda { |aspect_ids| joins(:contacts => :aspect_memberships). - where(:contacts => { :aspect_memberships => {:aspect_id => aspect_ids}}) + where(:aspect_memberships => {:aspect_id => aspect_ids}) } scope :profile_tagged_with, lambda{|tag_name| joins(:profile => :tags).where(:profile => {:tags => {:name => tag_name}}).where('profiles.searchable IS TRUE') }