[ACCEPTED]-How do I use functions like CONCAT(), etc. in ARel?-arel
Accepted answer
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
You can also use the Arel Extensions gem to have simpler 1 access to functions.
> User.where((User[:login] + User[:first_name]).length.in 2..10).to_sql
"SELECT `users`.* FROM `users`
WHERE LENGTH(CONCAT(CAST(`users`.`login` AS char),
CAST(`users`.`first_name` AS char)))
BETWEEN (2) AND (10)"
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.