Last active
March 2, 2023 08:40
-
-
Save isuke/92b81b8835a95404696dd8717f6d57c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task.select( | |
Arel::Nodes::NamedFunction.new( | |
'to_char', | |
[ | |
Task.arel_table[:created_at], | |
Arel::Nodes.build_quoted('YYYY') | |
] | |
).as('year') | |
) | |
# => SELECT to_char("tasks"."created_at", 'YYYY') AS year FROM "tasks" | |
Task.where( | |
Arel::Nodes::InfixOperation.new( | |
'->', | |
Task.arel_table['attr_values'], | |
Arel::Nodes.build_quoted('foo') | |
).eq( | |
'bar' | |
) | |
) | |
# => SELECT "tasks".* FROM "tasks" WHERE "tasks"."attr_values" -> 'foo' = 'bar' | |
Task.order(Arel::Nodes::InfixOperation.new('=', Task.arel_table['id'], 123).desc) | |
# => SELECT `tasks`.* FROM `companies` ORDER BY `tasks`.`id` = 123 DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment