Skip to content

Instantly share code, notes, and snippets.

@jdkealy
Created August 25, 2011 22:08
Show Gist options
  • Save jdkealy/1172125 to your computer and use it in GitHub Desktop.
Save jdkealy/1172125 to your computer and use it in GitHub Desktop.
def matches_dsl
if(self.gender_id == 1 && orientation_id == 1) then
[[2,1],[2,3]]
elsif(self.gender_id == 1 && orientation_id == 2) then
[[1,2],[1,3]]
elsif(self.gender_id == 1 && orientation_id == 3) then
[[1,2],[1,3],[2,1],[2,3]]
elsif(self.gender_id == 2 && orientation_id == 1) then
[[1,1],[1,3]]
elsif(self.gender_id == 2 && orientation_id == 2) then
[[2,2],[2,3]]
elsif(self.gender_id == 2 && orientation_id == 3) then
[[1,1],[1,3],[2,2],[2,3]]
end
end
def where_clause
clause = ""
matches_dsl.each_with_index do |f, i|
clause += "(gender_id = #{f[0]} AND orientation_id = #{f[1]})"
unless(i+1 == matches_dsl.size)
clause += " OR "
end
end
clause
end
def full_search_query
"select * from `users` p
WHERE
#{where_clause}"
end
def matches
User.find_by_sql("#{full_search_query}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment