ruby on rails - How to invoke a postgres function using arel? -
i have postgres function called 'move_to_end' i'm invoking using find_by_sql below:
def move_to_end self.class.find_by_sql ["select move_to_end(?)", id] end
i'd replace find_by_sql statement arel call, examples i've found require arel work table.
any thoughts on how accomplish appreciated.
you can using namedfunctions in arel. however, still have utilize arel_table reference table column in query. 1 possible workaround alias underscore:
# == schema info # # table name: solution # # solution_id :integer not null, primary key # body :text # class solution class << self alias_method :_, :arel_table def only_checked _.project(checked(_[:solution_id])) end def checked arel::nodes::namedfunction.new('checked', [query]) end end end solution.only_checked.to_sql # -> select checked("solution"."solution_id") "solution";
ruby-on-rails rails-activerecord arel
No comments:
Post a Comment