Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: active_record adapter #filter_array_eq and #filter_array_not_eq #404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/graphiti/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def filter_not_eq(scope, attribute, value)
alias_method :filter_uuid_not_eq, :filter_not_eq
alias_method :filter_enum_not_eq, :filter_not_eq

def filter_array_eq(scope, attribute, value)
if value.is_a?(Array)
value = value.map(&:to_s).join(',')
end
scope.where("#{attribute} @> ?", "{ #{value} }")
end

def filter_array_not_eq(scope, attribute, value)
if value.is_a?(Array)
value = value.map(&:to_s).join(',')
end
scope.where.not("#{attribute} @> ?", "{ #{value} }")
end

def filter_string_eq(scope, attribute, value, is_not: false)
column = column_for(scope, attribute)
clause = column.lower.eq_any(value.map(&:downcase))
Expand Down