Skip to content

Instantly share code, notes, and snippets.

@3014zhangshuo
Forked from iloveivyxuan/arel.rb
Created September 20, 2019 12:24
Show Gist options
  • Save 3014zhangshuo/04ec7b99c31cfe2be0b51d1f736658d7 to your computer and use it in GitHub Desktop.
Save 3014zhangshuo/04ec7b99c31cfe2be0b51d1f736658d7 to your computer and use it in GitHub Desktop.
Define Area Nodes -- Add a contain operator to Arel Nodes
# 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