Created
August 25, 2011 22:08
-
-
Save jdkealy/1172125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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