mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add Relation#table to get the relevant Arel::Table
This commit is contained in:
parent
d5f9173926
commit
93555c672e
1 changed files with 10 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue