aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/examples/performance.rb10
-rw-r--r--activerecord/lib/active_record/association_preload.rb12
-rwxr-xr-xactiverecord/lib/active_record/associations.rb4
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb2
-rwxr-xr-xactiverecord/lib/active_record/base.rb52
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb12
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb2
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb6
-rw-r--r--activerecord/lib/active_record/locale/en.yml2
-rw-r--r--activerecord/test/cases/defaults_test.rb2
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb14
-rw-r--r--activerecord/test/models/pirate.rb4
13 files changed, 51 insertions, 75 deletions
diff --git a/activerecord/examples/performance.rb b/activerecord/examples/performance.rb
index 53acd62f47..f69576b240 100755
--- a/activerecord/examples/performance.rb
+++ b/activerecord/examples/performance.rb
@@ -1,18 +1,18 @@
#!/usr/bin/env ruby -KU
TIMES = (ENV['N'] || 10000).to_i
-
require 'rubygems'
+
gem 'addressable', '~>2.0'
gem 'faker', '~>0.3.1'
gem 'rbench', '~>0.2.3'
+
require 'addressable/uri'
require 'faker'
require 'rbench'
-__DIR__ = File.dirname(__FILE__)
-$:.unshift "#{__DIR__}/../lib"
-require 'active_record'
+require File.expand_path("../../../load_paths", __FILE__)
+require "active_record"
conn = { :adapter => 'mysql',
:database => 'activerecord_unittest',
@@ -55,7 +55,7 @@ class Exhibit < ActiveRecord::Base
def self.feel(exhibits) exhibits.each { |e| e.feel } end
end
-sqlfile = "#{__DIR__}/performance.sql"
+sqlfile = File.expand_path("../performance.sql", __FILE__)
if File.exists?(sqlfile)
mysql_bin = %w[mysql mysql5].select { |bin| `which #{bin}`.length > 0 }
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 1f5217191c..f13c250ca4 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -6,7 +6,7 @@ module ActiveRecord
module AssociationPreload #:nodoc:
extend ActiveSupport::Concern
- # Implements the details of eager loading of ActiveRecord associations.
+ # Implements the details of eager loading of Active Record associations.
# Application developers should not use this module directly.
#
# ActiveRecord::Base is extended with this module. The source code in
@@ -18,7 +18,7 @@ module ActiveRecord
# The first one is by using table joins. This was only strategy available
# prior to Rails 2.1. Suppose that you have an Author model with columns
# 'name' and 'age', and a Book model with columns 'name' and 'sales'. Using
- # this strategy, ActiveRecord would try to retrieve all data for an author
+ # this strategy, Active Record would try to retrieve all data for an author
# and all of its books via a single query:
#
# SELECT * FROM authors
@@ -31,7 +31,7 @@ module ActiveRecord
# 'books' table is useful; the joined 'authors' data is just redundant, and
# processing this redundant data takes memory and CPU time. The problem
# quickly becomes worse and worse as the level of eager loading increases
- # (i.e. if ActiveRecord is to eager load the associations' associations as
+ # (i.e. if Active Record is to eager load the associations' associations as
# well).
#
# The second strategy is to use multiple database queries, one for each
@@ -45,7 +45,7 @@ module ActiveRecord
module ClassMethods
protected
- # Eager loads the named associations for the given ActiveRecord record(s).
+ # Eager loads the named associations for the given Active Record record(s).
#
# In this description, 'association name' shall refer to the name passed
# to an association creation method. For example, a model that specifies
@@ -80,7 +80,7 @@ module ActiveRecord
# { :author => :avatar }
# [ :books, { :author => :avatar } ]
#
- # +preload_options+ contains options that will be passed to ActiveRecord#find
+ # +preload_options+ contains options that will be passed to ActiveRecord::Base#find
# (which is called under the hood for preloading records). But it is passed
# only one level deep in the +associations+ argument, i.e. it's not passed
# to the child associations when +associations+ is a Hash.
@@ -166,7 +166,7 @@ module ActiveRecord
end
end
- # Given a collection of ActiveRecord objects, constructs a Hash which maps
+ # Given a collection of Active Record objects, constructs a Hash which maps
# the objects' IDs to the relevant objects. Returns a 2-tuple
# <tt>(id_to_record_map, ids)</tt> where +id_to_record_map+ is the Hash,
# and +ids+ is an Array of record IDs.
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index c1d06ff68d..680893a048 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -711,7 +711,7 @@ module ActiveRecord
#
# The +traps+ association on +Dungeon+ and the the +dungeon+ association on +Trap+ are the inverse of each other and the
# inverse of the +dungeon+ association on +EvilWizard+ is the +evil_wizard+ association on +Dungeon+ (and vice-versa). By default,
- # +ActiveRecord+ doesn't do know anything about these inverse relationships and so no object loading optimisation is possible. For example:
+ # Active Record doesn't know anything about these inverse relationships and so no object loading optimisation is possible. For example:
#
# d = Dungeon.first
# t = d.traps.first
@@ -721,7 +721,7 @@ module ActiveRecord
#
# The +Dungeon+ instances +d+ and <tt>t.dungeon</tt> in the above example refer to the same object data from the database, but are
# actually different in-memory copies of that data. Specifying the <tt>:inverse_of</tt> option on associations lets you tell
- # +ActiveRecord+ about inverse relationships and it will optimise object loading. For example, if we changed our model definitions to:
+ # Active Record about inverse relationships and it will optimise object loading. For example, if we changed our model definitions to:
#
# class Dungeon < ActiveRecord::Base
# has_many :traps, :inverse_of => :dungeon
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 5b68ca2edb..d9903243ce 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -388,7 +388,7 @@ module ActiveRecord
begin
if !loaded?
if @target.is_a?(Array) && @target.any?
- @target = find_target.map { |f| i = @target.index(f); i ? @target.delete_at(i) : f } + @target
+ @target = find_target + @target.find_all {|t| t.new_record? }
else
@target = find_target
end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 277ab785da..ce7259e96b 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -14,6 +14,7 @@ require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/string/behavior'
require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/module/introspection'
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/object/blank'
require 'arel'
@@ -647,29 +648,14 @@ module ActiveRecord #:nodoc:
reset_table_name
end
+ # Returns a quoted version of the table name, used to construct SQL statements.
def quoted_table_name
@quoted_table_name ||= connection.quote_table_name(table_name)
end
+ # Computes the table name, (re)sets it internally, and returns it.
def reset_table_name #:nodoc:
- base = base_class
-
- name =
- # STI subclasses always use their superclass' table.
- unless self == base
- base.table_name
- else
- # Nested classes are prefixed with singular parent table name.
- if parent < ActiveRecord::Base && !parent.abstract_class?
- contained = parent.table_name
- contained = contained.singularize if parent.pluralize_table_names
- contained << '_'
- end
- name = "#{full_table_name_prefix}#{contained}#{undecorated_table_name(base.name)}#{table_name_suffix}"
- end
-
- set_table_name(name)
- name
+ self.table_name = compute_table_name
end
def full_table_name_prefix #:nodoc:
@@ -1001,6 +987,23 @@ module ActiveRecord #:nodoc:
table_name
end
+ # Computes and returns a table name according to default conventions.
+ def compute_table_name
+ base = base_class
+ if self == base
+ # Nested classes are prefixed with singular parent table name.
+ if parent < ActiveRecord::Base && !parent.abstract_class?
+ contained = parent.table_name
+ contained = contained.singularize if parent.pluralize_table_names
+ contained << '_'
+ end
+ "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
+ else
+ # STI subclasses always use their superclass' table.
+ base.table_name
+ end
+ end
+
# Enables dynamic finders like <tt>find_by_user_name(user_name)</tt> and <tt>find_by_user_name_and_password(user_name, password)</tt>
# that are turned into <tt>where(:user_name => user_name).first</tt> and <tt>where(:user_name => user_name, :password => :password).first</tt>
# respectively. Also works for <tt>all</tt> by using <tt>find_all_by_amount(50)</tt> that is turned into <tt>where(:amount => 50).all</tt>.
@@ -1068,19 +1071,6 @@ module ActiveRecord #:nodoc:
attribute_names.all? { |name| column_methods_hash.include?(name.to_sym) }
end
- def attribute_condition(quoted_column_name, argument)
- case argument
- when nil then "#{quoted_column_name} IS ?"
- when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "#{quoted_column_name} IN (?)"
- when Range then if argument.exclude_end?
- "#{quoted_column_name} >= ? AND #{quoted_column_name} < ?"
- else
- "#{quoted_column_name} BETWEEN ? AND ?"
- end
- else "#{quoted_column_name} = ?"
- end
- end
-
protected
# Scope parameters to method calls within the block. Takes a hash of method_name => parameters hash.
# method_name may be <tt>:find</tt> or <tt>:create</tt>. <tt>:find</tt> parameter is <tt>Relation</tt> while
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 454d3e60e3..979ed52f4a 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -9,7 +9,7 @@ module ActiveRecord
end
module ConnectionAdapters
- # Connection pool base class for managing ActiveRecord database
+ # Connection pool base class for managing Active Record database
# connections.
#
# == Introduction
@@ -30,12 +30,12 @@ module ActiveRecord
# Connections can be obtained and used from a connection pool in several
# ways:
#
- # 1. Simply use ActiveRecord::Base.connection as with ActiveRecord 2.1 and
+ # 1. Simply use ActiveRecord::Base.connection as with Active Record 2.1 and
# earlier (pre-connection-pooling). Eventually, when you're done with
# the connection(s) and wish it to be returned to the pool, you call
# ActiveRecord::Base.clear_active_connections!. This will be the
- # default behavior for ActiveRecord when used in conjunction with
- # ActionPack's request handling cycle.
+ # default behavior for Active Record when used in conjunction with
+ # Action Pack's request handling cycle.
# 2. Manually check out a connection from the pool with
# ActiveRecord::Base.connection_pool.checkout. You are responsible for
# returning this connection to the pool when finished by calling
@@ -265,7 +265,7 @@ module ActiveRecord
end
# ConnectionHandler is a collection of ConnectionPool objects. It is used
- # for keeping separate connection pools for ActiveRecord models that connect
+ # for keeping separate connection pools for Active Record models that connect
# to different databases.
#
# For example, suppose that you have 5 models, with the following hierarchy:
@@ -285,7 +285,7 @@ module ActiveRecord
# is not the same as the one used by Book/ScaryBook/GoodBook.
#
# Normally there is only a single ConnectionHandler instance, accessible via
- # ActiveRecord::Base.connection_handler. ActiveRecord models use this to
+ # ActiveRecord::Base.connection_handler. Active Record models use this to
# determine that connection pool that they should use.
class ConnectionHandler
def initialize(pools = {})
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 db17bb348a..23c42d670b 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -103,7 +103,7 @@ module ActiveRecord
connection_handler.retrieve_connection(self)
end
- # Returns true if +ActiveRecord+ is connected.
+ # Returns true if Active Record is connected.
def connected?
connection_handler.connected?(self)
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index fecd4d590e..4ee9fee4a9 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -15,7 +15,7 @@ require 'active_record/connection_adapters/abstract/database_limits'
module ActiveRecord
module ConnectionAdapters # :nodoc:
- # ActiveRecord supports multiple database systems. AbstractAdapter and
+ # Active Record supports multiple database systems. AbstractAdapter and
# related classes form the abstraction layer which makes this possible.
# An AbstractAdapter represents a connection to a database, and provides an
# abstract interface for database-specific functionality such as establishing
@@ -59,7 +59,7 @@ module ActiveRecord
end
# Can this adapter determine the primary key for tables not attached
- # to an ActiveRecord class, such as join tables? Backend specific, as
+ # to an Active Record class, such as join tables? Backend specific, as
# the abstract adapter always returns +false+.
def supports_primary_key?
false
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 34aaff2b49..bb8850f134 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -224,7 +224,7 @@ module ActiveRecord
if @connection.respond_to?(:status)
@connection.status == PGconn::CONNECTION_OK
else
- # We're asking the driver, not ActiveRecord, so use @connection.query instead of #query
+ # We're asking the driver, not Active Record, so use @connection.query instead of #query
@connection.query 'SELECT 1'
true
end
@@ -258,7 +258,7 @@ module ActiveRecord
true
end
- # Does PostgreSQL support finding primary key on non-ActiveRecord tables?
+ # Does PostgreSQL support finding primary key on non-Active Record tables?
def supports_primary_key? #:nodoc:
true
end
@@ -925,7 +925,7 @@ module ActiveRecord
# Use standard-conforming strings if available so we don't have to do the E'...' dance.
set_standard_conforming_strings
- # If using ActiveRecord's time zone support configure the connection to return
+ # If using Active Record's time zone support configure the connection to return
# TIMESTAMP WITH ZONE types in UTC.
execute("SET time zone 'UTC'") if ActiveRecord::Base.default_timezone == :utc
end
diff --git a/activerecord/lib/active_record/locale/en.yml b/activerecord/lib/active_record/locale/en.yml
index 9d5cb54180..a0e94cbec1 100644
--- a/activerecord/lib/active_record/locale/en.yml
+++ b/activerecord/lib/active_record/locale/en.yml
@@ -4,7 +4,7 @@ en:
#created_at: "Created at"
#updated_at: "Updated at"
- # ActiveRecord models configuration
+ # Active Record models configuration
activerecord:
errors:
messages:
diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb
index 39aafa1ec7..ef29422824 100644
--- a/activerecord/test/cases/defaults_test.rb
+++ b/activerecord/test/cases/defaults_test.rb
@@ -43,7 +43,7 @@ if current_adapter?(:MysqlAdapter)
class DefaultsTestWithoutTransactionalFixtures < ActiveRecord::TestCase
# ActiveRecord::Base#create! (and #save and other related methods) will
# open a new transaction. When in transactional fixtures mode, this will
- # cause ActiveRecord to create a new savepoint. However, since MySQL doesn't
+ # cause Active Record to create a new savepoint. However, since MySQL doesn't
# support DDL transactions, creating a table will result in any created
# savepoints to be automatically released. This in turn causes the savepoint
# release code in AbstractAdapter#transaction to fail.
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index a87683bd97..685b11cb03 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -466,20 +466,6 @@ module NestedAttributesOnACollectionAssociationTests
assert_equal 'Grace OMalley', @child_1.reload.name
end
- def test_should_not_overwrite_unsaved_updates_when_loading_association
- @pirate.reload
- @pirate.send(association_setter, [{ :id => @child_1.id, :name => 'Grace OMalley' }])
- @pirate.send(@association_name).send(:load_target)
- assert_equal 'Grace OMalley', @pirate.send(@association_name).target.find { |r| r.id == @child_1.id }.name
- end
-
- def test_should_preserve_order_when_not_overwriting_unsaved_updates
- @pirate.reload
- @pirate.send(association_setter, [{ :id => @child_1.id, :name => 'Grace OMalley' }])
- @pirate.send(@association_name).send(:load_target)
- assert_equal @pirate.send(@association_name).target.first.id, @child_1.id
- end
-
def test_should_take_a_hash_with_composite_id_keys_and_assign_the_attributes_to_the_associated_models
@child_1.stubs(:id).returns('ABC1X')
@child_2.stubs(:id).returns('ABC2X')
diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb
index d89c8cf381..f1dbe32c6e 100644
--- a/activerecord/test/models/pirate.rb
+++ b/activerecord/test/models/pirate.rb
@@ -1,7 +1,7 @@
class Pirate < ActiveRecord::Base
belongs_to :parrot, :validate => true
belongs_to :non_validated_parrot, :class_name => 'Parrot'
- has_and_belongs_to_many :parrots, :validate => true, :order => 'parrots.id ASC'
+ has_and_belongs_to_many :parrots, :validate => true
has_and_belongs_to_many :non_validated_parrots, :class_name => 'Parrot'
has_and_belongs_to_many :parrots_with_method_callbacks, :class_name => "Parrot",
:before_add => :log_before_add,
@@ -21,7 +21,7 @@ class Pirate < ActiveRecord::Base
has_one :ship
has_one :update_only_ship, :class_name => 'Ship'
has_one :non_validated_ship, :class_name => 'Ship'
- has_many :birds, :order => 'birds.id ASC'
+ has_many :birds
has_many :birds_with_method_callbacks, :class_name => "Bird",
:before_add => :log_before_add,
:after_add => :log_after_add,