Skip to content

Commit

Permalink
Ignore blank arrays for condition values
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Dec 9, 2008
1 parent 0e2bc2b commit 5670574
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,8 @@
== 1.6.1 released 2008-12-8

* Group multi faceted conditions since we allow for the mix of "and" and "or"
* Blank arrays are not meaningful values for conditions

== 1.6.0 released 2008-12-8

* Converted all tree conditions to nested set conditions for performance reasons. A nested set data structure is now required instead of a tree
Expand Down
5 changes: 3 additions & 2 deletions lib/searchlogic/condition/base.rb
Expand Up @@ -90,7 +90,7 @@ def sanitize(alt_value = nil) # :nodoc:
return if value_is_meaningless?
v = alt_value || value
if v.is_a?(Array) && !self.class.handle_array_value?
merge_conditions(*v.collect { |i| sanitize(i) } << {:any => self.class.join_arrays_with_or?})
scope_condition(merge_conditions(*v.collect { |i| sanitize(i) } << {:any => self.class.join_arrays_with_or?}))
else
v = v.utc if column && v.respond_to?(:utc) && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
to_conditions(v)
Expand Down Expand Up @@ -121,7 +121,8 @@ def like_condition_name
def meaningless?(v)
case v
when Array
false
v.each { |i| return false unless meaningless?(i) }
true
else
!explicitly_set_value? || (self.class.ignore_meaningless_value? && v != false && v.blank?)
end
Expand Down
1 change: 0 additions & 1 deletion lib/searchlogic/conditions/magic_methods.rb
Expand Up @@ -245,7 +245,6 @@ def #{name}
def #{name}=(value)
@conditions = nil
#{name}_object.value = value
reset_#{name}! if #{name}_object.value_is_meaningless?
value
end
Expand Down
7 changes: 6 additions & 1 deletion test/condition_tests/equals_test.rb
Expand Up @@ -13,7 +13,12 @@ def test_sanitize

condition = Searchlogic::Condition::Equals.new(Account, :column => Account.columns_hash["id"])
condition.value = []
assert_equal [], condition.sanitize
assert_equal [], condition.value
assert_nil condition.sanitize

search = User.new_search
search.conditions.id = []
assert_equal [], search.conditions.id

condition = Searchlogic::Condition::Equals.new(Account, :column => Account.columns_hash["id"])
condition.value = (1..10)
Expand Down

0 comments on commit 5670574

Please sign in to comment.