diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-12 18:29:33 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-12 18:29:33 -0800 |
commit | c2cbe7bb27b6cd2e136ac06f4f36d6de0ec52459 (patch) | |
tree | 1d73b9dc98b535dd78c88d69187aaf07ab637e23 | |
parent | c1e223f8a9e7394ede2fcd5621f7d43721023a20 (diff) | |
download | rails-c2cbe7bb27b6cd2e136ac06f4f36d6de0ec52459.tar.gz rails-c2cbe7bb27b6cd2e136ac06f4f36d6de0ec52459.tar.bz2 rails-c2cbe7bb27b6cd2e136ac06f4f36d6de0ec52459.zip |
relation inclusion operator
-rw-r--r-- | lib/active_relation/predicates.rb | 20 | ||||
-rw-r--r-- | lib/active_relation/relations/order.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/projection.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/rename.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/selection.rb | 2 |
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 |