aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation
diff options
context:
space:
mode:
Diffstat (limited to 'lib/active_relation')
-rw-r--r--lib/active_relation/predicates.rb20
-rw-r--r--lib/active_relation/relations/order.rb2
-rw-r--r--lib/active_relation/relations/projection.rb4
-rw-r--r--lib/active_relation/relations/rename.rb2
-rw-r--r--lib/active_relation/relations/selection.rb2
5 files changed, 25 insertions, 5 deletions
diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb
index 6616cfd414..fba1cc90b6 100644
--- a/lib/active_relation/predicates.rb
+++ b/lib/active_relation/predicates.rb
@@ -40,15 +40,31 @@ module ActiveRelation
end
class GreaterThanOrEqualTo < Binary
+ protected
+ def predicate_sql
+ '>='
+ end
end
class GreaterThan < Binary
+ protected
+ def predicate_sql
+ '>'
+ end
end
class LessThanOrEqualTo < Binary
+ protected
+ def predicate_sql
+ '<='
+ end
end
class LessThan < Binary
+ protected
+ def predicate_sql
+ '<'
+ end
end
class Match < Base
@@ -69,6 +85,10 @@ module ActiveRelation
def ==(other)
super and attribute == other.attribute and relation == other.relation
end
+
+ def to_sql(options = {})
+ "#{attribute.to_sql} IN (#{relation.to_sql})"
+ end
end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/order.rb b/lib/active_relation/relations/order.rb
index c8034d2f17..bca81c1b6d 100644
--- a/lib/active_relation/relations/order.rb
+++ b/lib/active_relation/relations/order.rb
@@ -1,7 +1,7 @@
module ActiveRelation
module Relations
class Order < Compound
- attr_reader :relation, :orders
+ attr_reader :orders
def initialize(relation, *orders)
@relation, @orders = relation, orders
diff --git a/lib/active_relation/relations/projection.rb b/lib/active_relation/relations/projection.rb
index df25d16234..131db916f0 100644
--- a/lib/active_relation/relations/projection.rb
+++ b/lib/active_relation/relations/projection.rb
@@ -1,14 +1,14 @@
module ActiveRelation
module Relations
class Projection < Compound
- attr_reader :relation, :attributes
+ attr_reader :attributes
def initialize(relation, *attributes)
@relation, @attributes = relation, attributes
end
def ==(other)
- relation == other.relation and attributes == other.attributes
+ self.class == other.class and relation == other.relation and attributes == other.attributes
end
def qualify
diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb
index 8f28c94d52..c7b99c2127 100644
--- a/lib/active_relation/relations/rename.rb
+++ b/lib/active_relation/relations/rename.rb
@@ -1,7 +1,7 @@
module ActiveRelation
module Relations
class Rename < Compound
- attr_reader :relation, :schmattribute, :alias
+ attr_reader :schmattribute, :alias
def initialize(relation, renames)
@schmattribute, @alias = renames.shift
diff --git a/lib/active_relation/relations/selection.rb b/lib/active_relation/relations/selection.rb
index e102d105a0..e86dc627db 100644
--- a/lib/active_relation/relations/selection.rb
+++ b/lib/active_relation/relations/selection.rb
@@ -1,7 +1,7 @@
module ActiveRelation
module Relations
class Selection < Compound
- attr_reader :relation, :predicate
+ attr_reader :predicate
def initialize(relation, *predicates)
@predicate = predicates.shift