Join on contacts correctly in search

This commit is contained in:
Raphael 2011-01-20 12:05:25 -08:00
parent 4deec0cb38
commit 661d5e41a1

View file

@ -55,8 +55,15 @@ class Person < ActiveRecord::Base
sql << where_clause sql << where_clause
tokens.concat([token, token, token]) tokens.concat([token, token, token])
end end
#SELECT `people`.* FROM people
Person.searchable.where(sql, *tokens).includes(:contacts).order("contacts.user_id DESC", "profiles.last_name ASC", "profiles.first_name ASC", "people.diaspora_handle ASC") # INNER JOIN `profiles` ON `profiles`.person_id = `people`.id
# LEFT OUTER JOIN `contacts` ON (`contacts`.user_id = #{user.id} AND `contacts`.person_id = `people`.id)
# WHERE `profiles`.searchable = true AND
# `profiles`.first_name LIKE '%Max%'
# ORDER BY `contacts`.user_id DESC
Person.searchable.where(sql, *tokens).joins(
"LEFT OUTER JOIN `contacts` ON `contacts`.user_id = #{user.id} AND `contacts`.person_id = `people`.id"
).order("contacts.user_id DESC", "profiles.last_name ASC", "profiles.first_name ASC", "people.diaspora_handle ASC")
end end
def name def name