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
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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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