Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
- index f0bad6c..0e6f2c4 100755
- --- a/activerecord/lib/active_record/associations.rb
- +++ b/activerecord/lib/active_record/associations.rb
- @@ -2228,11 +2228,13 @@ module ActiveRecord
- def relation
- if reflection.macro == :has_and_belongs_to_many
- - [Arel::Table.new(table_alias_for(options[:join_table], aliased_join_table_name)), Arel::Table.new(table_name_and_alias)]
- + [Arel::Table.new(table_alias_for(options[:join_table], aliased_join_table_name), reflection.klass.arel_engine),
- + Arel::Table.new(table_name_and_alias, reflection.klass.arel_engine)]
- elsif reflection.options[:through]
- - [Arel::Table.new(table_alias_for(through_reflection.klass.table_name, aliased_join_table_name)), Arel::Table.new(table_name_and_alias)]
- + [Arel::Table.new(table_alias_for(through_reflection.klass.table_name, aliased_join_table_name), through_reflection.klass.arel_engine),
- + Arel::Table.new(table_name_and_alias, reflection.klass.arel_engine)]
- else
- - Arel::Table.new(table_name_and_alias)
- + Arel::Table.new(table_name_and_alias, reflection.klass.arel_engine)
- end
- end
- diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
- index 07c5545..17b2b9b 100755
- --- a/activerecord/lib/active_record/base.rb
- +++ b/activerecord/lib/active_record/base.rb
- @@ -1506,7 +1506,15 @@ module ActiveRecord #:nodoc:
- end
- def arel_table(table = nil)
- - Relation.new(self, Arel::Table.new(table || table_name))
- + table = Arel::Table.new(table || table_name, arel_engine)
- +
- + relation = Relation.new(self, table)
- + relation.table = table
- + relation
- + end
- +
- + def arel_engine
- + @arel_engine ||= Arel::Sql::Engine.new(self)
- end
- private
- diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
- index ae03e1d..65462e8 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
- @@ -57,7 +57,8 @@ module ActiveRecord
- :conditions => where_clause,
- :limit => @relation.taken,
- :offset => @relation.skipped,
- - :from => (@relation.send(:from_clauses) if @relation.send(:sources).present?)
- + :from => (@relation.send(:from_clauses) if @relation.send(:sources).present?),
- + :relation => table
- },
- ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, @eager_load_associations, nil))
- rescue ThrowResult
- @@ -129,9 +130,14 @@ 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, @klass.arel_engine)
- + end
- +
- protected
- def method_missing(method, *args, &block)
- @@ -157,5 +163,9 @@ module ActiveRecord
- @relation.send(:where_clauses).join(join_string)
- end
- + def primary_key
- + @klass.primary_key
- + end
- +
- end
- end
- diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
- index 7a1d6fc..56a51e3 100644
- --- a/activerecord/lib/active_record/relation/finder_methods.rb
- +++ b/activerecord/lib/active_record/relation/finder_methods.rb
- @@ -78,7 +78,7 @@ module ActiveRecord
- end
- def find_one(id)
- - record = where(@klass.primary_key => id).first
- + record = where(table[primary_key].eq(id)).first
- unless record
- conditions = where_clause(', ')
- @@ -90,7 +90,8 @@ module ActiveRecord
- end
- def find_some(ids)
- - result = where(@klass.primary_key => ids).all
- + predicate = Arel::Predicates::In.new(table[primary_key], ids)
- + result = where(predicate).all
- expected_size =
- if @relation.taken && ids.size > @relation.taken
Add Comment
Please, Sign In to add comment