From aa5c9a19826c84bbb9c9f75f8d1a4b04b874780c Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 16 Mar 2008 16:53:49 -0700 Subject: 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 --- lib/active_relation/extensions/array.rb | 4 ++++ lib/active_relation/extensions/range.rb | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 lib/active_relation/extensions/range.rb (limited to 'lib/active_relation/extensions') 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 -- cgit v1.2.3