-
-
Save 3014zhangshuo/04ec7b99c31cfe2be0b51d1f736658d7 to your computer and use it in GitHub Desktop.
Define Area Nodes -- Add a contain operator to Arel Nodes
This file contains hidden or 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