diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-20 10:11:07 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-20 10:11:07 -0700 |
commit | 41f80e494af3ce7c8f3d6aa34f8303524a48373b (patch) | |
tree | 30b458021856fe436af8b17a457353356b286f1c /lib | |
parent | 2d021c641ab8c9215df863531cfb0d8ff8b9554a (diff) | |
download | rails-41f80e494af3ce7c8f3d6aa34f8303524a48373b.tar.gz rails-41f80e494af3ce7c8f3d6aa34f8303524a48373b.tar.bz2 rails-41f80e494af3ce7c8f3d6aa34f8303524a48373b.zip |
limits and offsets need to be externalized too. first draft
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/predicates.rb | 7 | ||||
-rw-r--r-- | lib/arel/relations/operations/group.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/operations/join.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/operations/project.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/operations/skip.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/operations/take.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/utilities/aggregation.rb | 8 | ||||
-rw-r--r-- | lib/arel/relations/utilities/compound.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/writes/delete.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/writes/update.rb | 2 |
10 files changed, 22 insertions, 17 deletions
diff --git a/lib/arel/predicates.rb b/lib/arel/predicates.rb index f21376d4c9..a83bad3c22 100644 --- a/lib/arel/predicates.rb +++ b/lib/arel/predicates.rb @@ -3,11 +3,8 @@ module Arel end class Binary < Predicate - attr_reader :operand1, :operand2 - - def initialize(operand1, operand2) - @operand1, @operand2 = operand1, operand2 - end + attributes :operand1, :operand2 + deriving :initialize def ==(other) self.class === other and diff --git a/lib/arel/relations/operations/group.rb b/lib/arel/relations/operations/group.rb index 22af2734a6..253c4215b6 100644 --- a/lib/arel/relations/operations/group.rb +++ b/lib/arel/relations/operations/group.rb @@ -8,7 +8,7 @@ module Arel @groupings = (groupings + (block_given?? [yield(self)] : [])).collect { |g| g.bind(relation) } end - def aggregation? + def externalizable? true end end diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/relations/operations/join.rb index 243a0289c7..8025db095e 100644 --- a/lib/arel/relations/operations/join.rb +++ b/lib/arel/relations/operations/join.rb @@ -39,8 +39,8 @@ module Arel end # TESTME - def aggregation? - relation1.aggregation? or relation2.aggregation? + def externalizable? + relation1.externalizable? or relation2.externalizable? end def join? diff --git a/lib/arel/relations/operations/project.rb b/lib/arel/relations/operations/project.rb index 2be87fe694..c92a9df5a5 100644 --- a/lib/arel/relations/operations/project.rb +++ b/lib/arel/relations/operations/project.rb @@ -12,8 +12,8 @@ module Arel @attributes ||= projections.collect { |p| p.bind(self) } end - def aggregation? - attributes.any?(&:aggregation?) + def externalizable? + attributes.any?(&:aggregation?) or relation.externalizable? end end end
\ No newline at end of file diff --git a/lib/arel/relations/operations/skip.rb b/lib/arel/relations/operations/skip.rb index ea5df21f53..930e4c94ea 100644 --- a/lib/arel/relations/operations/skip.rb +++ b/lib/arel/relations/operations/skip.rb @@ -2,5 +2,9 @@ module Arel class Skip < Compound attributes :relation, :skipped deriving :initialize, :== + + def externalizable? + true + end end end
\ No newline at end of file diff --git a/lib/arel/relations/operations/take.rb b/lib/arel/relations/operations/take.rb index 095e430417..2fd3fdf635 100644 --- a/lib/arel/relations/operations/take.rb +++ b/lib/arel/relations/operations/take.rb @@ -2,5 +2,9 @@ module Arel class Take < Compound attributes :relation, :taken deriving :initialize, :== + + def externalizable? + true + end end end
\ No newline at end of file diff --git a/lib/arel/relations/utilities/aggregation.rb b/lib/arel/relations/utilities/aggregation.rb index 9f5ead8f86..bdc7650a20 100644 --- a/lib/arel/relations/utilities/aggregation.rb +++ b/lib/arel/relations/utilities/aggregation.rb @@ -1,5 +1,5 @@ module Arel - class Aggregation < Compound + class Externalization < Compound attributes :relation deriving :initialize, :== include Recursion::BaseCase @@ -17,16 +17,16 @@ module Arel end def name - relation.name + '_aggregation' + relation.name + '_external' end end class Relation def externalize - @externalized ||= aggregation?? Aggregation.new(self) : self + @externalized ||= externalizable?? Externalization.new(self) : self end - def aggregation? + def externalizable? false end end diff --git a/lib/arel/relations/utilities/compound.rb b/lib/arel/relations/utilities/compound.rb index 23a55d4b5b..a91cec1127 100644 --- a/lib/arel/relations/utilities/compound.rb +++ b/lib/arel/relations/utilities/compound.rb @@ -2,7 +2,7 @@ module Arel class Compound < Relation attr_reader :relation hash_on :relation - delegate :joins, :join?, :inserts, :taken, :skipped, :name, :aggregation?, + delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?, :column_for, :engine, :table, :table_sql, :to => :relation diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/relations/writes/delete.rb index e72679c4d6..318a299b8b 100644 --- a/lib/arel/relations/writes/delete.rb +++ b/lib/arel/relations/writes/delete.rb @@ -8,7 +8,7 @@ module Arel "DELETE", "FROM #{table_sql}", ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), - ("LIMIT #{taken}" unless taken.blank? ), + ("LIMIT #{taken}" unless taken.blank? ), ].compact.join("\n") end diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb index 18b7ad9de1..720b9d697d 100644 --- a/lib/arel/relations/writes/update.rb +++ b/lib/arel/relations/writes/update.rb @@ -14,7 +14,7 @@ module Arel "#{value.format(attribute)} = #{attribute.format(value)}" end.join(",\n"), ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), - ("LIMIT #{taken}" unless taken.blank? ) + ("LIMIT #{taken}" unless taken.blank? ) ].join("\n") end |