How do I use functions like CONCAT(), etc. in ARel?

前端 未结 1 1581
忘掉有多难
忘掉有多难 2021-01-02 06:57

Is there a way to have ARel write (sanitized, possibly aliased, etc.) column names into CONCAT() and other SQL functions?

Here\'s how to do

相关标签:
1条回答
  • 2021-01-02 07:24

    Use NamedFunction:

    name = Arel::Attribute.new(Arel::Table.new(:countries), :name)
    func = Arel::Nodes::NamedFunction.new 'zomg', [name]
    Country.select([name, func]).to_sql
    
    0 讨论(0)
提交回复
热议问题