aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-21 18:47:22 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-21 18:47:22 -0800
commit559d9bbfe09034e807e5eae169bea26df780aa36 (patch)
tree472c35a20a5d331961e6ed1488373646c9574e60 /lib
parentd62ace142ce873c72eb916f5a14aa33a67ecfb86 (diff)
downloadrails-559d9bbfe09034e807e5eae169bea26df780aa36.tar.gz
rails-559d9bbfe09034e807e5eae169bea26df780aa36.tar.bz2
rails-559d9bbfe09034e807e5eae169bea26df780aa36.zip
merging "schmoin" experiment with joining aggregations into regular "join" functionality; half-way done...
Diffstat (limited to 'lib')
-rw-r--r--lib/active_relation/relations/compound.rb2
-rw-r--r--lib/active_relation/relations/group.rb4
-rw-r--r--lib/active_relation/relations/join.rb18
-rw-r--r--lib/active_relation/relations/relation.rb4
4 files changed, 22 insertions, 6 deletions
diff --git a/lib/active_relation/relations/compound.rb b/lib/active_relation/relations/compound.rb
index e870f12aff..a7595c9e3d 100644
--- a/lib/active_relation/relations/compound.rb
+++ b/lib/active_relation/relations/compound.rb
@@ -2,7 +2,7 @@ module ActiveRelation
class Compound < Relation
attr_reader :relation
- delegate :projections, :attribute, :joins, :selects, :orders, :groupings, :table_sql, :inserts, :limit, :offset, :name, :alias,
+ delegate :projections, :attribute, :joins, :selects, :orders, :groupings, :table_sql, :inserts, :limit, :offset, :name, :alias, :aggregation?,
:to => :relation
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/group.rb b/lib/active_relation/relations/group.rb
index bc363970c7..31de6f4bd8 100644
--- a/lib/active_relation/relations/group.rb
+++ b/lib/active_relation/relations/group.rb
@@ -13,5 +13,9 @@ module ActiveRelation
def qualify
Group.new(relation.qualify, *groupings.collect(&:qualify))
end
+
+ def aggregation?
+ true
+ end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb
index b624df8d72..d4cfe19239 100644
--- a/lib/active_relation/relations/join.rb
+++ b/lib/active_relation/relations/join.rb
@@ -26,18 +26,26 @@ module ActiveRelation
relation1.send(:selects) + relation2.send(:selects)
end
+ # this is magick!!!
+ def projections
+ relation1.send(:projections) + relation2.attributes
+ end
+
def attribute(name)
relation1[name] || relation2[name]
end
-
- protected
- def projections
- relation1.send(:projections) + relation2.send(:projections)
- end
private
def join
"#{join_sql} #{relation2.send(:table_sql)} ON #{predicates.collect { |p| p.to_sql(Sql::Predicate.new) }.join(' AND ')}"
end
+
+ def join
+ [join_sql, right_table, "ON", predicates.collect { |p| p.to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ")
+ end
+
+ def right_table
+ relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql)
+ end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb
index f1febc497c..cb981eb3de 100644
--- a/lib/active_relation/relations/relation.rb
+++ b/lib/active_relation/relations/relation.rb
@@ -80,6 +80,10 @@ module ActiveRelation
def attributes
projections.collect(&:to_attribute)
end
+
+ def aggregation?
+ false
+ end
def to_sql(strategy = Sql::Select.new)
strategy.select [