aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-01 00:56:49 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-01 00:56:49 +0530
commit93555c672e3edd5705eb381f2bf3d4f93cffa96f (patch)
tree97b06f2d044c247c28598509427c7cd99b9cb285 /activerecord/lib/active_record/relation.rb
parentd5f9173926598ace058b502e00c49f6477820509 (diff)
downloadrails-93555c672e3edd5705eb381f2bf3d4f93cffa96f.tar.gz
rails-93555c672e3edd5705eb381f2bf3d4f93cffa96f.tar.bz2
rails-93555c672e3edd5705eb381f2bf3d4f93cffa96f.zip
Add Relation#table to get the relevant Arel::Table
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 502aa909ab..6a1237cdd1 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -6,7 +6,7 @@ module ActiveRecord
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 @@ module ActiveRecord
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)