Skip to content

Instantly share code, notes, and snippets.

@envygeeks
Last active June 8, 2019 02:43
Show Gist options
  • Save envygeeks/897d4f66303985db16ef to your computer and use it in GitHub Desktop.
Save envygeeks/897d4f66303985db16ef to your computer and use it in GitHub Desktop.
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