Permalink
Browse files

Add Relation#table to get the relevant Arel::Table

  • Loading branch information...
lifo committed Dec 31, 2009
1 parent d5f9173 commit 93555c672e3edd5705eb381f2bf3d4f93cffa96f
Showing with 10 additions and 1 deletion.
  1. +10 −1 activerecord/lib/active_record/relation.rb
@@ -6,7 +6,7 @@ class Relation
delegate :length, :collect, :map, :each, :all?, :to => :to_a
attr_reader :relation, :klass, :preload_associations, :eager_load_associations
- attr_writer :readonly, :preload_associations, :eager_load_associations
+ attr_writer :readonly, :preload_associations, :eager_load_associations, :table
def initialize(klass, relation)
@klass, @relation = klass, relation
@@ -133,9 +133,18 @@ def spawn(relation = @relation)
relation.readonly = @readonly
relation.preload_associations = @preload_associations
relation.eager_load_associations = @eager_load_associations
+ relation.table = table
relation
end
+ def table
+ @table ||= Arel::Table.new(@klass.table_name, Arel::Sql::Engine.new(@klass))
+ end
+
+ def primary_key
+ @primary_key ||= table[@klass.primary_key]
+ end
+
protected
def method_missing(method, *args, &block)

0 comments on commit 93555c6

Please sign in to comment.