如何在ARel中使用CONCAT()等函数?

有没有办法让ARel写入(清理,可能是别名等)列名到CONCAT()和其他SQL函数中?

以下是使用AVG()的方法 …

 ?> name = Arel::Attribute.new(Arel::Table.new(:countries), :name) => # population = Arel::Attribute.new(Arel::Table.new(:countries), :population) => # Country.select([name, population.average]).to_sql => "SELECT `countries`.`name`, AVG(`countries`.`population`) AS avg_id FROM `countries`" 

(是的,我知道avg_id在每一行都是一样的,只是试图说明我的问题)

那么如果我想要一个不同的function呢?

 ?> Country.select(xyz).to_sql # Arel::Concat.new(name, population) or something? => "SELECT CONCAT(`countries`.`name`, ' ', `countries`.`population`) AS concat_id FROM `countries`" 

谢谢!

使用NamedFunction

 name = Arel::Attribute.new(Arel::Table.new(:countries), :name) func = Arel::Nodes::NamedFunction.new 'zomg', [name] Country.select([name, func]).to_sql