From 8d82bef58a002b4441d86d0b08e7a5fd493c7e39 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Mon, 14 Jun 2010 12:01:00 -0300 Subject: Documentation for #quoted_table_name method Signed-off-by: Xavier Noria --- activerecord/lib/active_record/base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 63ab6efae2..110f131e6c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -647,10 +647,12 @@ 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, resets it internally, and returns it. def reset_table_name #:nodoc: base = base_class -- cgit v1.2.3 From 4a8c8804ff267db8fb4fcf147b8a4eeed78db209 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Jun 2010 18:36:04 +0200 Subject: refactors AR::Base#reset_table_name --- activerecord/lib/active_record/base.rb | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 110f131e6c..3b6ffa46f2 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' @@ -652,26 +653,9 @@ module ActiveRecord #:nodoc: @quoted_table_name ||= connection.quote_table_name(table_name) end - # Computes the table name, resets it internally, and returns it. + # 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: @@ -1003,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 find_by_user_name(user_name) and find_by_user_name_and_password(user_name, password) # that are turned into where(:user_name => user_name).first and where(:user_name => user_name, :password => :password).first # respectively. Also works for all by using find_all_by_amount(50) that is turned into where(:amount => 50).all. -- cgit v1.2.3 From f17159b02996ef478fd2376f1c88adf33a1a1b78 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Jun 2010 23:21:53 +0200 Subject: edit pass: the names of Rails components have a space, ie, "Active Record", not "ActiveRecord" --- activerecord/lib/active_record/association_preload.rb | 12 ++++++------ activerecord/lib/active_record/associations.rb | 4 ++-- .../connection_adapters/abstract/connection_pool.rb | 12 ++++++------ .../connection_adapters/abstract/connection_specification.rb | 2 +- .../active_record/connection_adapters/abstract_adapter.rb | 4 ++-- .../active_record/connection_adapters/postgresql_adapter.rb | 6 +++--- activerecord/lib/active_record/locale/en.yml | 2 +- activerecord/test/cases/defaults_test.rb | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) (limited to 'activerecord') 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 # (id_to_record_map, ids) 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 c1e16d08cb..9b59266bbc 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 t.dungeon 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 :inverse_of 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/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. -- cgit v1.2.3