Skip to content

Commit

Permalink
Merge pull request #2675 from HashNotAdam/hotfix/fix_presence_filteri…
Browse files Browse the repository at this point in the history
…ng_on_boolean_columns

Issue #1099: Filtering on "Is present" and "Is blank" on boolean columns
  • Loading branch information
mshibuya committed Aug 22, 2016
2 parents ba2088c + 3e78509 commit f919c03
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 121 deletions.
20 changes: 19 additions & 1 deletion lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ class StatementBuilder < RailsAdmin::AbstractModel::StatementBuilder
protected

def unary_operators
case @type
when :boolean
boolean_unary_operators
else
generic_unary_operators
end
end

private

def generic_unary_operators
{
'_blank' => ["(#{@column} IS NULL OR #{@column} = '')"],
'_present' => ["(#{@column} IS NOT NULL AND #{@column} != '')"],
Expand All @@ -165,7 +176,14 @@ def unary_operators
}
end

private
def boolean_unary_operators
generic_unary_operators.merge(
'_blank' => ["(#{@column} IS NULL)"],
'_empty' => ["(#{@column} IS NULL)"],
'_present' => ["(#{@column} IS NOT NULL)"],
'_not_empty' => ["(#{@column} IS NOT NULL)"],
)
end

def range_filter(min, max)
if min && max
Expand Down
Loading

0 comments on commit f919c03

Please sign in to comment.