Fix ActiveRecord queries with nested hashes

Rails 3.2.6 doesn't like them
This commit is contained in:
Steven Hancock 2012-06-13 14:18:09 -07:00
parent a2ccf685ca
commit 79b7d38158
2 changed files with 6 additions and 5 deletions

View file

@ -69,10 +69,10 @@ class Contact < ActiveRecord::Base
def contacts def contacts
people = Person.arel_table people = Person.arel_table
incoming_aspects = Aspect.joins(:contacts).where( incoming_aspects = Aspect.where(
:user_id => self.person.owner_id, :user_id => self.person.owner_id,
:contacts_visible => true, :contacts_visible => true).joins(:contacts).where(
:contacts => {:person_id => self.user.person.id}).select('aspects.id') :contacts => {:person_id => self.user.person.id}).select('aspects.id')
incoming_aspect_ids = incoming_aspects.map{|a| a.id} incoming_aspect_ids = incoming_aspects.map{|a| a.id}
similar_contacts = Person.joins(:contacts => :aspect_memberships).where( 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.*') :aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT people.*')

View file

@ -71,7 +71,8 @@ class Person < ActiveRecord::Base
# @note user is passed in here defensively # @note user is passed in here defensively
scope :all_from_aspects, lambda { |aspect_ids, user| scope :all_from_aspects, lambda { |aspect_ids, user|
joins(:contacts => :aspect_memberships). 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| scope :unique_from_aspects, lambda{ |aspect_ids, user|
@ -81,7 +82,7 @@ class Person < ActiveRecord::Base
#not defensive #not defensive
scope :in_aspects, lambda { |aspect_ids| scope :in_aspects, lambda { |aspect_ids|
joins(:contacts => :aspect_memberships). 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') } scope :profile_tagged_with, lambda{|tag_name| joins(:profile => :tags).where(:profile => {:tags => {:name => tag_name}}).where('profiles.searchable IS TRUE') }