diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 338d5d2afe309d4d728386eda4b41ccd0a9ebabb..67d24b35d1a1151c0b8b4f83b4a026753666b3cf 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -117,7 +117,7 @@ def klass # Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the # through association's scope) def target_scope - AssociationRelation.new(klass, klass.arel_table, self).merge!(klass.all) + AssociationRelation.create(klass, klass.arel_table, self).merge!(klass.all) end # Loads the \target if needed and returns it. diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 6ddbd4955dc32f8eb173b2546a643830aa731dd8..b4047b08bc39a062bc638a7f54df391a8f5cced5 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -34,7 +34,7 @@ def reader(force_reload = false) reload end - @proxy ||= CollectionProxy.new(klass, self) + @proxy ||= CollectionProxy.create(klass, self) end # Implements the writer method, e.g. foo.items= for Foo.has_many :items diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index 8c528af399d93774e8019a0efa4a0d83e9badd79..58fc00d81174b4cab379e4df7b67d544ef785a50 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -105,13 +105,13 @@ def join_constraints if item.is_a?(Relation) item else - ActiveRecord::Relation.new(klass, table).instance_exec(self, &item) + ActiveRecord::Relation.create(klass, table).instance_exec(self, &item) end end if reflection.type scope_chain_items << - ActiveRecord::Relation.new(klass, table) + ActiveRecord::Relation.create(klass, table) .where(reflection.type => foreign_klass.base_class.name) end diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 82bf426b22fcb6b1fd8c013df1b371b4aa9f2a2d..2317e34bc0ecce213fc9a0295cef3a168f29f63e 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -85,7 +85,7 @@ class Preloader #:nodoc: def initialize(records, associations, preload_scope = nil) @records = Array.wrap(records).compact.uniq @associations = Array.wrap(associations) - @preload_scope = preload_scope || Relation.new(nil, nil) + @preload_scope = preload_scope || Relation.create(nil, nil) end def run diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index c6b7da2e3c339fb89506a04c4d5e192ada207209..e088021112f4e50dba87c67d37b0131534c26b76 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -146,7 +146,7 @@ def arel_engine private def relation #:nodoc: - relation = Relation.new(self, arel_table) + relation = Relation.create(self, arel_table) if finder_needs_type_condition? relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name) diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 44ea8610f2458e65c8a2b22d12431ef4ca33ad64..23541d1d27c82973fb4766db1e2cf7de5e22de1e 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -124,7 +124,7 @@ def table_name=(value) @quoted_table_name = nil @arel_table = nil @sequence_name = nil unless defined?(@explicit_sequence_name) && @explicit_sequence_name - @relation = Relation.new(self, arel_table) + @relation = Relation.create(self, arel_table) end # Returns a quoted version of the table name, used to construct SQL statements. diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index 8d6740246cd2a394dde6f154e8d6cb693a91d660..7ed65a548c50c88bfb5c4eebfa5d912d06a77053 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -73,10 +73,8 @@ def method_missing(method, *args, &block) module ClassMethods # :nodoc: @@subclasses = ThreadSafe::Cache.new(:initial_capacity => 2) - def new(klass, *args) - relation = relation_class_for(klass).allocate - relation.__send__(:initialize, klass, *args) - relation + def create(klass, *args) + relation_class_for(klass).new(klass, *args) end # This doesn't have to be thread-safe. relation_class_for guarantees that this will only be diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index da13152e01ca30d001ee79b0080265439cb0fa89..c08158d38b64e3236b234ba75beab10e814f3c9d 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -22,7 +22,7 @@ def merge # build a relation to merge in rather than directly merging # the values. def other - other = Relation.new(relation.klass, relation.table) + other = Relation.create(relation.klass, relation.table) hash.each { |k, v| if k == :joins if Hash === v diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index c63ae9c9fb010b1073ce681c82ddf4a950bae71f..2552cbd234877e2b14585b3f6b6f6ef721a50386 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -64,7 +64,7 @@ def only(*onlies) private def relation_with(values) # :nodoc: - result = Relation.new(klass, table, values) + result = Relation.create(klass, table, values) result.extend(*extending_values) if extending_values.any? result end