-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow negation #8
Conversation
@@ -17,15 +17,15 @@ class Comment < ActiveRecord::Base | |||
belongs_to :post | |||
|
|||
filterable_by :post_id, :user_id | |||
filterable_by :post_author_id do |scope, value| | |||
scope.joins(:posts).where(:'posts.author_id' => value) | |||
filterable_by :post_author_id do |value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the big change is that you don't now need scope
as a block argument, but the old method is still supported (although deprecated)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will we still be able to handle when value is nil cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value cannot be nil, these blocks are only run unless value.bank?
Comment.filter_by({ 'post_id' => ['1', '2'] }) | ||
# => WHERE post_id IN (1, 2) | ||
|
||
Comment.filter_by({ 'post_id_not' => '3' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other change is that you now can append _not
and exclude something
@@ -17,15 +17,15 @@ class Comment < ActiveRecord::Base | |||
belongs_to :post | |||
|
|||
filterable_by :post_id, :user_id | |||
filterable_by :post_author_id do |scope, value| | |||
scope.joins(:posts).where(:'posts.author_id' => value) | |||
filterable_by :post_author_id do |value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will we still be able to handle when value is nil cases?
@@ -17,15 +17,15 @@ class Comment < ActiveRecord::Base | |||
belongs_to :post | |||
|
|||
filterable_by :post_id, :user_id | |||
filterable_by :post_author_id do |scope, value| | |||
scope.joins(:posts).where(:'posts.author_id' => value) | |||
filterable_by :post_author_id do |value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value cannot be nil, these blocks are only run unless value.bank?
def self.merge(scope, unscoped, hash, name, **opts, &block) | ||
key = name | ||
positive = normalize(hash[key]) if hash.key?(key) | ||
if positive.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andyborn here we only apply block/limit scope if params['post_author_id']
is present
|
||
key = "#{name}_not" | ||
negative = normalize(hash[key]) if hash.key?(key) | ||
if negative.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with params['post_author_id_not']
Released v0.6.0 |
It's a bigger change than it may seem, will explain inline