1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

relation inclusion operator

This commit is contained in:
Nick Kallen 2008-01-12 18:29:33 -08:00
parent c1e223f8a9
commit c2cbe7bb27
5 changed files with 25 additions and 5 deletions

View file

@ -40,15 +40,31 @@ module ActiveRelation
end end
class GreaterThanOrEqualTo < Binary class GreaterThanOrEqualTo < Binary
protected
def predicate_sql
'>='
end
end end
class GreaterThan < Binary class GreaterThan < Binary
protected
def predicate_sql
'>'
end
end end
class LessThanOrEqualTo < Binary class LessThanOrEqualTo < Binary
protected
def predicate_sql
'<='
end
end end
class LessThan < Binary class LessThan < Binary
protected
def predicate_sql
'<'
end
end end
class Match < Base class Match < Base
@ -69,6 +85,10 @@ module ActiveRelation
def ==(other) def ==(other)
super and attribute == other.attribute and relation == other.relation super and attribute == other.attribute and relation == other.relation
end end
def to_sql(options = {})
"#{attribute.to_sql} IN (#{relation.to_sql})"
end
end end
end end
end end

View file

@ -1,7 +1,7 @@
module ActiveRelation module ActiveRelation
module Relations module Relations
class Order < Compound class Order < Compound
attr_reader :relation, :orders attr_reader :orders
def initialize(relation, *orders) def initialize(relation, *orders)
@relation, @orders = relation, orders @relation, @orders = relation, orders

View file

@ -1,14 +1,14 @@
module ActiveRelation module ActiveRelation
module Relations module Relations
class Projection < Compound class Projection < Compound
attr_reader :relation, :attributes attr_reader :attributes
def initialize(relation, *attributes) def initialize(relation, *attributes)
@relation, @attributes = relation, attributes @relation, @attributes = relation, attributes
end end
def ==(other) def ==(other)
relation == other.relation and attributes == other.attributes self.class == other.class and relation == other.relation and attributes == other.attributes
end end
def qualify def qualify

View file

@ -1,7 +1,7 @@
module ActiveRelation module ActiveRelation
module Relations module Relations
class Rename < Compound class Rename < Compound
attr_reader :relation, :schmattribute, :alias attr_reader :schmattribute, :alias
def initialize(relation, renames) def initialize(relation, renames)
@schmattribute, @alias = renames.shift @schmattribute, @alias = renames.shift

View file

@ -1,7 +1,7 @@
module ActiveRelation module ActiveRelation
module Relations module Relations
class Selection < Compound class Selection < Compound
attr_reader :relation, :predicate attr_reader :predicate
def initialize(relation, *predicates) def initialize(relation, *predicates)
@predicate = predicates.shift @predicate = predicates.shift