Last active
June 8, 2019 02:43
-
-
Save envygeeks/897d4f66303985db16ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Post < ActiveRecord::Base | |
class << self | |
def get_column(column) | |
columns.select do |column_| | |
column_.name == column.to_s | |
end[0] | |
end | |
def any(what) | |
out = all | |
what.each.with_index(1) do |(key_, value_), index_| | |
key_ = get_column(key_) || raise(ActiveRecord::PreparedStatementInvalid, "no column #{key_}") | |
out = out.where(<<-SQL.strip_heredoc.strip).bind([key_, value_]) | |
$#{index_} = ANY("#{table_name}"."#{key_.name}") | |
SQL | |
end | |
out | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment