diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 20:47:02 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 20:47:02 -0700 |
commit | 89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8 (patch) | |
tree | 2e7fe3a9a814bc0ffacc48c50e0bc4d5de18bb0d /lib | |
parent | 9771b2f3a3fdb45517a132228a1129718acd2fac (diff) | |
download | rails-89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8.tar.gz rails-89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8.tar.bz2 rails-89b354bf97d0a981376d36f2f8a7ba6a87fe2aa8.zip |
added attribute.eq(nil)
- produces attribute IS NULL
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/extensions.rb | 3 | ||||
-rw-r--r-- | lib/active_relation/extensions/array.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/extensions/nil_class.rb | 5 | ||||
-rw-r--r-- | lib/active_relation/extensions/object.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/extensions/range.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/predicates.rb | 6 | ||||
-rw-r--r-- | lib/active_relation/primitives/value.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 2 |
8 files changed, 19 insertions, 7 deletions
diff --git a/lib/active_relation/extensions.rb b/lib/active_relation/extensions.rb index 21d6724004..ded830eb8c 100644 --- a/lib/active_relation/extensions.rb +++ b/lib/active_relation/extensions.rb @@ -2,4 +2,5 @@ require 'active_relation/extensions/object' require 'active_relation/extensions/class' require 'active_relation/extensions/array' require 'active_relation/extensions/hash' -require 'active_relation/extensions/range'
\ No newline at end of file +require 'active_relation/extensions/range' +require 'active_relation/extensions/nil_class'
\ No newline at end of file diff --git a/lib/active_relation/extensions/array.rb b/lib/active_relation/extensions/array.rb index 2af5832707..793c06aad8 100644 --- a/lib/active_relation/extensions/array.rb +++ b/lib/active_relation/extensions/array.rb @@ -7,7 +7,7 @@ class Array "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")" end - def predicate_sql + def inclusion_predicate_sql "IN" end end
\ No newline at end of file diff --git a/lib/active_relation/extensions/nil_class.rb b/lib/active_relation/extensions/nil_class.rb new file mode 100644 index 0000000000..729c4cada7 --- /dev/null +++ b/lib/active_relation/extensions/nil_class.rb @@ -0,0 +1,5 @@ +class NilClass + def equality_predicate_sql + 'IS' + end +end
\ No newline at end of file diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb index cd51543c91..25cef989a4 100644 --- a/lib/active_relation/extensions/object.rb +++ b/lib/active_relation/extensions/object.rb @@ -7,6 +7,10 @@ class Object formatter.scalar self end + def equality_predicate_sql + '=' + end + def metaclass class << self self diff --git a/lib/active_relation/extensions/range.rb b/lib/active_relation/extensions/range.rb index 0218a0ab44..d7329efe34 100644 --- a/lib/active_relation/extensions/range.rb +++ b/lib/active_relation/extensions/range.rb @@ -3,7 +3,7 @@ class Range formatter.range self.begin, self.end end - def predicate_sql + def inclusion_predicate_sql "BETWEEN" end end
\ No newline at end of file diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb index 6fcef3cfd6..22fbcd9f0b 100644 --- a/lib/active_relation/predicates.rb +++ b/lib/active_relation/predicates.rb @@ -41,7 +41,7 @@ module ActiveRelation end def predicate_sql - '=' + operand2.equality_predicate_sql end end @@ -74,6 +74,8 @@ module ActiveRelation end class In < Binary - delegate :predicate_sql, :to => :operand2 + def predicate_sql + operand2.inclusion_predicate_sql + end end end
\ No newline at end of file diff --git a/lib/active_relation/primitives/value.rb b/lib/active_relation/primitives/value.rb index aeee89dc3b..6f251d442b 100644 --- a/lib/active_relation/primitives/value.rb +++ b/lib/active_relation/primitives/value.rb @@ -2,7 +2,7 @@ module ActiveRelation class Value attr_reader :value, :relation - delegate :predicate_sql, :to => :value + delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value def initialize(value, relation) @value, @relation = value, relation diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index 88d1bce4a8..db61fce3de 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -115,7 +115,7 @@ module ActiveRelation end alias_method :to_s, :to_sql - def predicate_sql + def inclusion_predicate_sql "IN" end |