Created
August 15, 2017 06:49
-
-
Save iloveivyxuan/7dfbfc40b2e3c658148bbb52075c614f to your computer and use it in GitHub Desktop.
Define Area Nodes -- Add a contain operator to Arel Nodes
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
# app/config/initializers/arel.rb | |
require 'arel/nodes/binary' | |
require 'arel/predications' | |
require 'arel/visitors/postgresql' | |
module Arel | |
class Nodes::ContainsArray < Arel::Nodes::Binary | |
def operator | |
:"@>" | |
end | |
end | |
class Visitors::PostgreSQL | |
private | |
def visit_Arel_Nodes_ContainsArray(o, collector) | |
infix_value o, collector, ' @> ' | |
end | |
end | |
module Predications | |
def contains(other) | |
Nodes::ContainsArray.new self, Nodes.build_quoted(other, self) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment