From af27262ec308784d2aaa59d48fd43bef5c2b9f89 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 4 Mar 2011 21:21:34 +0000 Subject: Fix a couple of tests in join_model_test.rb which were failing when the identity map is turned off --- activerecord/lib/active_record/associations/association.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 86904ea2bc..67752da2a5 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -191,8 +191,8 @@ module ActiveRecord else attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key] - if options[:as] - attributes["#{options[:as]}_type"] = owner.class.base_class.name + if reflection.options[:as] + attributes[reflection.type] = owner.class.base_class.name end end attributes -- cgit v1.2.3 From 8987cda2bb64fe289f7a28b2833a2786cfbc8259 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 4 Mar 2011 22:29:40 +0000 Subject: When preloading has_and_belongs_to_many associations, we should only instantiate one AR object per actual record in the database. (Even when IM is off.) --- .../active_record/associations/preloader/has_and_belongs_to_many.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb index e794f05340..24be279449 100644 --- a/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb @@ -31,10 +31,12 @@ module ActiveRecord private # Once we have used the join table column (in super), we manually instantiate the - # actual records + # actual records, ensuring that we don't create more than one instances of the same + # record def associated_records_by_owner + records = {} super.each do |owner_key, rows| - rows.map! { |row| klass.instantiate(row) } + rows.map! { |row| records[row[klass.primary_key]] ||= klass.instantiate(row) } end end -- cgit v1.2.3 From 3b10b8a201d9fbef831be81d7a4bc9b82c75a6f4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 Mar 2011 01:10:00 +0100 Subject: implements ActiveRecord::Base.connection_config to be able to check the configuration of the current connection at runtime --- .../connection_adapters/abstract/connection_specification.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb index 3716937689..d88720c8bf 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -89,6 +89,16 @@ module ActiveRecord retrieve_connection end + # Returns the configuration of the associated connection as a hash: + # + # ActiveRecord::Base.connection_config + # # => {:pool=>5, :timeout=>5000, :database=>"db/development.sqlite3", :adapter=>"sqlite3"} + # + # Please use only for reading. + def connection_config + connection_pool.spec.config + end + def connection_pool connection_handler.retrieve_connection_pool(self) end -- cgit v1.2.3 From 045ca303947e7e9209cee4b3fdede05f6dbb02c4 Mon Sep 17 00:00:00 2001 From: mjy Date: Thu, 3 Mar 2011 13:28:26 -0500 Subject: fixes a missmatched column in example --- activerecord/lib/active_record/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index b3204b2bda..4db08c774b 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -463,7 +463,7 @@ module ActiveRecord #:nodoc: # # # You can use the same string replacement techniques as you can with ActiveRecord#find # Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date] - # > [#"The Cheap Man Buys Twice"}>, ...] + # > [#"The Cheap Man Buys Twice"}>, ...] def find_by_sql(sql, binds = []) connection.select_all(sanitize_sql(sql), "#{name} Load", binds).collect! { |record| instantiate(record) } end -- cgit v1.2.3 From a1b4d8e7b277ddcfba6c31cbb9245025123cf04b Mon Sep 17 00:00:00 2001 From: "R.T. Lechow" Date: Thu, 3 Mar 2011 23:54:58 -0500 Subject: Active Record typos. --- activerecord/lib/active_record/associations/association.rb | 4 ++-- activerecord/lib/active_record/autosave_association.rb | 2 +- activerecord/lib/active_record/callbacks.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 67752da2a5..25b4b9d90d 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -7,7 +7,7 @@ module ActiveRecord # This is the root class of all associations ('+ Foo' signifies an included module Foo): # # Association - # SingularAssociaton + # SingularAssociation # HasOneAssociation # HasOneThroughAssociation + ThroughAssociation # BelongsToAssociation @@ -88,7 +88,7 @@ module ActiveRecord # Construct the scope for this association. # - # Note that the association_scope is merged into the targed_scope only when the + # Note that the association_scope is merged into the target_scope only when the # scoped method is called. This is because at that point the call may be surrounded # by scope.scoping { ... } or with_scope { ... } etc, which affects the scope which # actually gets built. diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 748cc99a62..48dbe0838a 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -4,7 +4,7 @@ module ActiveRecord # = Active Record Autosave Association # # +AutosaveAssociation+ is a module that takes care of automatically saving - # associacted records when their parent is saved. In addition to saving, it + # associated records when their parent is saved. In addition to saving, it # also destroys any associated records that were marked for destruction. # (See +mark_for_destruction+ and marked_for_destruction?). # diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index ff4ce1b605..86d58df99b 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -73,7 +73,7 @@ module ActiveRecord # # Now, when Topic#destroy is run only +destroy_author+ is called. When Reply#destroy is # run, both +destroy_author+ and +destroy_readers+ are called. Contrast this to the following situation - # where the +before_destroy+ methis is overriden: + # where the +before_destroy+ method is overridden: # # class Topic < ActiveRecord::Base # def before_destroy() destroy_author end -- cgit v1.2.3 From 74818a35432b40fef16fe74f248ea75d35405324 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 5 Mar 2011 11:56:24 -0800 Subject: use Arel::Table#alias rather than passing the :as parameter --- activerecord/lib/active_record/base.rb | 4 ++-- activerecord/lib/active_record/relation/predicate_builder.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4db08c774b..a5e1c91f47 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -636,7 +636,7 @@ module ActiveRecord #:nodoc: @quoted_table_name = nil define_attr_method :table_name, value, &block - @arel_table = Arel::Table.new(table_name, :engine => arel_engine) + @arel_table = Arel::Table.new(table_name, arel_engine) @relation = Relation.new(self, arel_table) end alias :table_name= :set_table_name @@ -1321,7 +1321,7 @@ MSG def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name) attrs = expand_hash_conditions_for_aggregates(attrs) - table = Arel::Table.new(self.table_name, :engine => arel_engine, :as => default_table_name) + table = Arel::Table.new(table_name).alias(default_table_name) viz = Arel::Visitors.for(arel_engine) PredicateBuilder.build_from_hash(arel_engine, attrs, table).map { |b| viz.accept b diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 9633fd3d82..982b3d7e9f 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -5,14 +5,14 @@ module ActiveRecord table = default_table if value.is_a?(Hash) - table = Arel::Table.new(column, :engine => engine) + table = Arel::Table.new(column, engine) build_from_hash(engine, value, table) else column = column.to_s if column.include?('.') table_name, column = column.split('.', 2) - table = Arel::Table.new(table_name, :engine => engine) + table = Arel::Table.new(table_name, engine) end attribute = table[column.to_sym] -- cgit v1.2.3