有没有办法ARel将(清理,可能是别名等)列名称写入CONCAT()其他SQL函数?
以下是使用AVG()的方法 ...
?> name = Arel::Attribute.new(Arel::Table.new(:countries), :name)
=> #<struct Arel::Attributes::Attribute [...]
?> population = Arel::Attribute.new(Arel::Table.new(:countries), :population)
=> #<struct Arel::Attributes::Attribute [...]
?> Country.select([name, population.average]).to_sql
=> "SELECT `countries`.`name`, AVG(`countries`.`population`) AS avg_id FROM `countries`"
Run Code Online (Sandbox Code Playgroud)
(是的,我知道avg_id每一行都是一样的,只是想说明我的问题)
那么如果我想要一个不同的功能呢?
?> Country.select(xyz).to_sql # Arel::Concat.new(name, population) or something?
=> "SELECT CONCAT(`countries`.`name`, ' ', `countries`.`population`) AS concat_id FROM `countries`"
Run Code Online (Sandbox Code Playgroud)
谢谢!