aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation/extensions
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-16 16:53:49 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-16 16:53:49 -0700
commitaa5c9a19826c84bbb9c9f75f8d1a4b04b874780c (patch)
treec5a6720db91fed575f9fbd0b8de08de651def91c /lib/active_relation/extensions
parent07f7f752fecb56316456f144c121e471fd0d0847 (diff)
downloadrails-aa5c9a19826c84bbb9c9f75f8d1a4b04b874780c.tar.gz
rails-aa5c9a19826c84bbb9c9f75f8d1a4b04b874780c.tar.bz2
rails-aa5c9a19826c84bbb9c9f75f8d1a4b04b874780c.zip
added support for `attribute IN ...` and `attribute BETWEEN ...`
- IN and BETWEEN are chosen depending on the type of the second operand - ranges (1..2), arrays ([1,2,3]), and relations ("SELECT * ...") are all supported
Diffstat (limited to 'lib/active_relation/extensions')
-rw-r--r--lib/active_relation/extensions/array.rb4
-rw-r--r--lib/active_relation/extensions/range.rb9
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/active_relation/extensions/array.rb b/lib/active_relation/extensions/array.rb
index c07819d35f..2af5832707 100644
--- a/lib/active_relation/extensions/array.rb
+++ b/lib/active_relation/extensions/array.rb
@@ -6,4 +6,8 @@ class Array
def to_sql(formatter = nil)
"(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")"
end
+
+ def predicate_sql
+ "IN"
+ end
end \ No newline at end of file
diff --git a/lib/active_relation/extensions/range.rb b/lib/active_relation/extensions/range.rb
new file mode 100644
index 0000000000..0218a0ab44
--- /dev/null
+++ b/lib/active_relation/extensions/range.rb
@@ -0,0 +1,9 @@
+class Range
+ def to_sql(formatter = nil)
+ formatter.range self.begin, self.end
+ end
+
+ def predicate_sql
+ "BETWEEN"
+ end
+end \ No newline at end of file