123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Base

Overview

Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.

See the mapping rules in table_name and the full example in README for more insight.

Creation

Active Records accept constructor parameters either in a hash or as a block. The hash method is especially useful when you're receiving the data from somewhere else, like an HTTP request. It works like this:

user = User.new(name: "David", occupation: "Code Artist")
user.name # => "David"

You can also use block initialization:

user = User.new do |u|
  u.name = "David"
  u.occupation = "Code Artist"
end

And of course you can just create a bare object and specify the attributes after the fact:

user = User.new
user.name = "David"
user.occupation = "Code Artist"

Conditions

Conditions can either be specified as a string, array, or hash representing the WHERE-part of an SQL statement. The array form is to be used when the condition input is tainted and requires sanitization. The string form can be used for statements that don't involve tainted data. The hash form works much like the array form, except only equality and range is possible. Examples:

class User < ActiveRecord::Base
  def self.authenticate_unsafely(user_name, password)
    where("user_name = '#{user_name}' AND password = '#{password}'").first
  end

  def self.authenticate_safely(user_name, password)
    where("user_name = ? AND password = ?", user_name, password).first
  end

  def self.authenticate_safely_simply(user_name, password)
    where(user_name: user_name, password: password).first
  end
end

The authenticate_unsafely method inserts the parameters directly into the query and is thus susceptible to SQL-injection attacks if the user_name and password parameters come directly from an HTTP request. The authenticate_safely and authenticate_safely_simply both will sanitize the user_name and password before inserting them in the query, which will ensure that an attacker can't escape the query and fake the login (or worse).

When using multiple parameters in the conditions, it can easily become hard to read exactly what the fourth or fifth question mark is supposed to represent. In those cases, you can resort to named bind variables instead. That's done by replacing the question marks with symbols and supplying a hash with values for the matching symbol keys:

Company.where(
  "id = :id AND name = :name AND division = :division AND created_at > :accounting_date",
  { id: 3, name: "37signals", division: "First", accounting_date: '2005-01-01' }
).first

Similarly, a simple hash without a statement will generate conditions based on equality with the SQL AND operator. For instance:

Student.where(first_name: "Harvey", status: 1)
Student.where(params[:student])

A range may be used in the hash to use the SQL BETWEEN operator:

Student.where(grade: 9..12)

An array may be used in the hash to use the SQL IN operator:

Student.where(grade: [9,11,12])

When joining tables, nested hashes or keys written in the form 'table_name.column_name' can be used to qualify the table name of a particular condition. For instance:

Student.joins(:schools).where(schools: { category: 'public' })
Student.joins(:schools).where('schools.category' => 'public' )

Overwriting default accessors

All column values are automatically available through basic accessors on the Active Record object, but sometimes you want to specialize this behavior. This can be done by overwriting the default accessors (using the same name as the attribute) and calling super to actually change things.

class Song < ActiveRecord::Base
  # Uses an integer of seconds to hold the length of the song

  def length=(minutes)
    super(minutes.to_i * 60)
  end

  def length
    super / 60
  end
end

You can alternatively use self[:attribute]=(value) and self[:attribute] or write_attribute(:attribute, value) and read_attribute(:attribute).

Attribute query methods

In addition to the basic accessors, query methods are also automatically available on the Active Record object. Query methods allow you to test whether an attribute value is present. For numeric values, present is defined as non-zero.

For example, an Active Record User with the name attribute has a name? method that you can call to determine whether the user has a name:

user = User.new(name: "David")
user.name? # => true

anonymous = User.new(name: "")
anonymous.name? # => false

Accessing attributes before they have been typecasted

Sometimes you want to be able to read the raw attribute data without having the column-determined typecast run its course first. That can be done by using the <attribute>_before_type_cast accessors that all attributes have. For example, if your Account model has a balance attribute, you can call account.balance_before_type_cast or account.id_before_type_cast.

This is especially useful in validation situations where the user might supply a string for an integer field and you want to display the original string back in an error message. Accessing the attribute normally would typecast the string to 0, which isn't what you want.

Dynamic attribute-based finders

Dynamic attribute-based finders are a mildly deprecated way of getting (and/or creating) objects by simple queries without turning to SQL. They work by appending the name of an attribute to find_by_ like Person.find_by_user_name. Instead of writing Person.find_by(user_name: user_name), you can use Person.find_by_user_name(user_name).

It's possible to add an exclamation point (!) on the end of the dynamic finders to get them to raise an RecordNotFound error if they do not return any records, like Person.find_by_last_name!.

It's also possible to use multiple attributes in the same find by separating them with “and”.

Person.find_by(user_name: user_name, password: password)
Person.find_by_user_name_and_password(user_name, password) # with dynamic finder

It's even possible to call these dynamic finder methods on relations and named scopes.

Payment.order("created_on").find_by_amount(50)

Saving arrays, hashes, and other non-mappable objects in text columns

Active Record can serialize any object in text columns using YAML. To do so, you must specify this with a call to the class method serialize. This makes it possible to store arrays, hashes, and other non-mappable objects without doing any additional work.

class User < ActiveRecord::Base
  serialize :preferences
end

user = User.create(preferences: { "background" => "black", "display" => large })
User.find(user.id).preferences # => { "background" => "black", "display" => large }

You can also specify a class option as the second parameter that'll raise an exception if a serialized object is retrieved as a descendant of a class not in the hierarchy.

class User < ActiveRecord::Base
  serialize :preferences, Hash
end

user = User.create(preferences: %w( one two three ))
User.find(user.id).preferences    # raises SerializationTypeMismatch

When you specify a class option, the default value for that attribute will be a new instance of that class.

class User < ActiveRecord::Base
  serialize :preferences, OpenStruct
end

user = User.new
user.preferences.theme_color = "red"

Single table inheritance

Active Record allows inheritance by storing the name of the class in a column that is named “type” by default. See Inheritance for more details.

Connection to multiple databases in different models

Connections are usually created through ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. All classes inheriting from Base will use this connection. But you can also set a class-specific connection. For example, if Course is an Base, but resides in a different database, you can just say Course.establish_connection and Course and all of its subclasses will use this connection instead.

This feature is implemented by keeping a connection pool in Base that is a ::Hash indexed by the class. If a connection is requested, the retrieve_connection method will go up the class-hierarchy until a connection is found in the connection pool.

Exceptions

  • ActiveRecordError - Generic error class and superclass of all other errors raised by Active Record.

  • AdapterNotSpecified - The configuration hash used in establish_connection didn't include an :adapter key.

  • AdapterNotFound - The :adapter key used in establish_connection specified a non-existent adapter (or a bad spelling of an existing one).

  • AssociationTypeMismatch - The object assigned to the association wasn't of the type specified in the association definition.

  • AttributeAssignmentError - An error occurred while doing a mass assignment through the attributes= method. You can inspect the attribute property of the exception object to determine which attribute triggered the error.

  • ConnectionNotEstablished - No connection has been established. Use establish_connection before querying.

  • MultiparameterAssignmentErrors - Collection of errors that occurred during a mass assignment using the attributes= method. The errors property of this exception contains an array of AttributeAssignmentError objects that should be inspected to determine which attributes triggered the errors.

  • RecordInvalid - raised by save! and create! when the record is invalid.

  • RecordNotFound - No record responded to the find method. Either the row with the given ID doesn't exist or the row didn't meet the additional restrictions. Some find calls do not raise this exception to signal nothing was found, please check its documentation for further details.

  • SerializationTypeMismatch - The serialized object wasn't of the class specified as the second parameter.

  • StatementInvalid - The database server rejected the SQL statement. The precise error is added in the message.

Note: The attributes listed are class-level attributes (accessible from both the class and instance level). So it's possible to assign a logger to the class through .logger= which will then be used by all instances in the current object space.

Constant Summary

::ActiveModel::AttributeMethods - Included

CALL_COMPILABLE_REGEXP, NAME_COMPILABLE_REGEXP

AttributeMethods - Included

AttrNames, BLACKLISTED_CLASS_METHODS

AttributeMethods::Read - self

ID, ReaderMethodCache

AttributeMethods::Write - self

WriterMethodCache

Callbacks - Included

CALLBACKS

::ActiveModel::SecurePassword - Included

MAX_PASSWORD_LENGTH_ALLOWED

Callback Registration

AttributeDecorators - Attributes & Methods

AttributeMethods - Attributes & Methods

Attributes - Attributes & Methods

Core - Attributes & Methods

Inheritance - Attributes & Methods

Integration - Attributes & Methods

ModelSchema - Attributes & Methods

NestedAttributes - Attributes & Methods

ReadonlyAttributes - Attributes & Methods

Reflection - Attributes & Methods

Store - Attributes & Methods

Timestamp - Attributes & Methods

Transactions - Attributes & Methods

Locking::Optimistic - Attributes & Methods

Class Attribute Summary

Class Method Summary

Delegation::DelegateCache - Extended

Enum - Extended

::ActiveModel::Translation - Included

human_attribute_name

Transforms attribute names into a more human format, such as “First name” instead of “first_name”.

i18n_scope

Returns the i18n_scope for the class.

lookup_ancestors

When localizing a string, it goes through the lookup returned by this method, which is used in ActiveModel::Name#human, ActiveModel::Errors#full_messages and ActiveModel::Translation#human_attribute_name.

Querying - Extended

any?,
count_by_sql

Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part.

exists?, fifth!, find_by!,
find_by_sql

Executes a custom SQL query against your database and returns all the results.

find_or_create_by!, first!, first_or_create!, forty_two!, fourth!, last!, many?, second!, take!, third!

QueryCache::ClassMethods - Extended

cache

Enable the query cache within the block if Active Record is configured.

uncached

Disable the query cache within the block if Active Record is configured.

ConnectionHandling - Extended

clear_active_connections!, clear_all_connections!, clear_reloadable_connections!,
connection

Returns the connection currently associated with the class.

connection_config

Returns the configuration of the associated connection as a hash:

connection_pool,
establish_connection

Establishes the connection to the database.

remove_connection, retrieve_connection

::ActiveSupport::DescendantsTracker - Extended

::ActiveSupport::Benchmarkable - Extended

benchmark

Allows you to measure the execution time of a block in a template and records the result to the log.

::ActiveModel::Naming - Extended

model_name

Returns an ::ActiveModel::Name object for module.

Instance Attribute Summary

Serialization - Included

NoTouching - Included

AutosaveAssociation - Included

#changed_for_autosave?

Returns whether or not this record has been changed in any way (including whether any of its nested autosave associations are likewise changed).

#destroyed_by_association

Returns the association for the parent being destroyed.

#destroyed_by_association=

Records the association that is being destroyed and destroying this record in the process.

#marked_for_destruction?

Returns whether or not this record will be destroyed as part of the parents save transaction.

::ActiveModel::Dirty - Included

#attribute_aliases, #attribute_aliases?, #attribute_method_matchers, #attribute_method_matchers?,
#changed?

Returns true if any attribute have unsaved changes, false otherwise.

AttributeMethods::PrimaryKey - self

#id

Returns the primary key value.

#id=

Sets the primary key value.

#id?

Queries the primary key value.

AttributeMethods - Included

Validations - Included

AttributeAssignment - Included

Persistence - Included

#destroyed?

Returns true if this object has been destroyed, otherwise returns false.

#new_record?

Returns true if this object hasn't been saved yet – that is, a record for the object doesn't exist in the database yet; otherwise, returns false.

#persisted?

Returns true if the record is persisted, i.e.

Core - Included

#frozen?

Returns true if the attributes hash has been frozen.

#readonly?

Returns true if the record is read only.

Instance Method Summary

Serialization - Included

#serializable_hash,
#to_xml

Builds an XML document to represent the model.

::ActiveModel::Serializers::Xml - Included

#from_xml

Sets the model attributes from an XML string.

#to_xml

Returns XML representing the model.

::ActiveModel::Serializers::JSON - Included

#as_json

Returns a hash representing the model.

#from_json

Sets the model attributes from a JSON string.

::ActiveModel::Serialization - Included

#serializable_hash

Returns a serialized hash of your object.

Transactions - Included

#add_to_transaction

Add the record to the current transaction so that the .after_rollback and .after_commit callbacks can be called.

#rollback_active_record_state!

Reset id and @new_record if the transaction rolls back.

#transaction

See Transactions::ClassMethods for detailed documentation.

#with_transaction_returning_status

Executes method within a transaction and captures its return value as a status flag.

AutosaveAssociation - Included

#mark_for_destruction

Marks this record to be destroyed as part of the parents save transaction.

#reload

Reloads the attributes of the object as usual and clears marked_for_destruction flag.

::ActiveModel::Dirty - Included

#changed

Returns an array with the name of the attributes with unsaved changes.

#changed_attributes

Returns a hash of the attributes with unsaved changes indicating their original values like attr => original value.

#changes

Returns a hash of changed attributes indicating their original and new values like attr => [original value, new value].

#previous_changes

Returns a hash of attributes that were changed before the model was saved.

#restore_attributes

Restore all previous data of the provided attributes.

#changes_applied

Removes current changes and makes them accessible through previous_changes.

#clear_attribute_changes

Remove changes information for the provided attributes.

#clear_changes_information

Clear all dirty data: current changes and previous changes.

AttributeMethods::PrimaryKey - self

#id_before_type_cast

Returns the primary key value before type cast.

#id_was

Returns the primary key previous value.

#to_key

Returns this record's primary key value wrapped in an ::Array if one is available.

AttributeMethods::Query - self

AttributeMethods::BeforeTypeCast - self

#attributes_before_type_cast

Returns a hash of attributes before typecasting and deserialization.

#read_attribute_before_type_cast

Returns the value of the attribute identified by attr_name before typecasting and deserialization.

AttributeMethods::Write - self

#raw_write_attribute,
#write_attribute

Updates the attribute identified by attr_name with the specified value.

AttributeMethods::Read - self

#read_attribute

Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a date column is cast to a date object, like Date.new(2004, 12, 12)).

AttributeMethods - Included

#[]

Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a date column is cast to a date object, like Date.new(2004, 12, 12)).

#[]=

Updates the attribute identified by attr_name with the specified value.

#attribute_for_inspect

Returns an #inspect-like string for the value of the attribute attr_name.

#attribute_names

Returns an array of names for the attributes available on this object.

#attribute_present?

Returns true if the specified attribute has been set by the user or by a database load and is neither nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings).

#attributes

Returns a hash of all the attributes with their names as keys and the values of the attributes as values.

#has_attribute?

Returns true if the given attribute is in the attributes hash, otherwise false.

#respond_to?

A Person object with a name attribute can ask person.respond_to?(:name), person.respond_to?(:name=), and person.respond_to?(:name?) which will all return true.

::ActiveModel::AttributeMethods - Included

#attribute_missing

attribute_missing is like method_missing, but for attributes.

#method_missing

Allows access to the object attributes, which are held in the hash returned by attributes, as though they were first-class methods.

#respond_to?,
#respond_to_without_attributes?

A Person instance with a name attribute can ask person.respond_to?(:name), person.respond_to?(:name=), and person.respond_to?(:name?) which will all return true.

Locking::Pessimistic - Included

#lock!

Obtain a row lock on this record.

#with_lock

Wraps the passed block in a transaction, locking the object before yielding.

Validations - Included

#save

The validation process on save can be skipped by passing validate: false.

#save!

Attempts to save the record just like Base#save but will raise a RecordInvalid exception instead of returning false if the record is not valid.

#valid?

Runs all the validations within the specified context.

#validate
#validate!

Runs all the validations within the specified context.

::ActiveModel::Validations::HelperMethods - Included

#validates_absence_of

Validates that the specified attributes are blank (as defined by Object#blank?).

#validates_acceptance_of

Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement).

#validates_confirmation_of

Encapsulates the pattern of wanting to validate a password or email address field with a confirmation.

#validates_exclusion_of

Validates that the value of the specified attribute is not in a particular enumerable object.

#validates_format_of

Validates whether the value of the specified attribute is of the correct form, going by the regular expression provided.

#validates_inclusion_of

Validates whether the value of the specified attribute is available in a particular enumerable object.

#validates_length_of

Validates that the specified attribute matches the length restrictions supplied.

#validates_numericality_of

Validates whether the value of the specified attribute is numeric by trying to convert it to a float with Kernel.Float (if only_integer is false) or applying it to the regular expression /\A[+\-]?\d+\Z/ (if only_integer is set to true).

#validates_presence_of

Validates that the specified attributes are not blank (as defined by Object#blank?).

#validates_size_of

::ActiveModel::Validations - Included

#errors

Returns the Errors object that holds all information about attribute error messages.

#invalid?

Performs the opposite of valid?.

#read_attribute_for_validation

Hook method defining how an attribute value should be retrieved.

#valid?

Runs all the specified validations and returns true if no errors were added otherwise false.

#validate
#validates_with

Passes the record off to the class or classes specified and allows them to add errors based on more complex conditions.

Integration - Included

#cache_key

Returns a cache key that can be used to identify this record.

#to_param

Returns a ::String, which Action Pack uses for constructing an URL to this object.

::ActiveModel::Conversion - Included

#to_key

Returns an ::Array of all key attributes if any is set, regardless if the object is persisted or not.

#to_model

If your object is already designed to implement all of the Active Model you can use the default :to_model implementation, which simply returns self.

#to_param

Returns a string representing the object's key suitable for use in URLs, or nil if persisted? is false.

#to_partial_path

Returns a string identifying the path associated with the object.

AttributeAssignment - Included

#assign_attributes

Allows you to set all the attributes by passing in a hash of attributes with keys matching the attribute names (which again matches the column names).

Sanitization - Included

#quoted_id

TODO: Deprecate this.

Scoping - Included

Inheritance - Included

Persistence - Included

#becomes

Returns an instance of the specified klass with the attributes of the current record.

#becomes!

Wrapper around becomes that also changes the instance's sti column value.

#decrement

Initializes attribute to zero if nil and subtracts the value passed as by (default is 1).

#decrement!

Wrapper around decrement that saves the record.

#delete

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

#destroy

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

#destroy!

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).

#increment

Initializes attribute to zero if nil and adds the value passed as by (default is 1).

#increment!

Wrapper around increment that saves the record.

#reload

Reloads the record from the database.

#save

Saves the model.

#save!

Saves the model.

#toggle

Assigns to attribute the boolean opposite of attribute?.

#toggle!

Wrapper around toggle that saves the record.

#touch

Saves the record with the updated_at/on attributes set to the current time.

#update

Updates the attributes of the model from the passed-in hash and saves the record, all wrapped in a transaction.

#update!

Updates its receiver just like update but calls save! instead of save, so an exception is raised if the record is invalid.

#update_attribute

Updates a single attribute and saves the record.

#update_attributes
#update_attributes!
#update_column

Equivalent to update_columns(name => value).

#update_columns

Updates the attributes directly in the database issuing an UPDATE SQL statement and sets them in the receiver:

Core - Included

#<=>

Allows sort on objects.

#==

Returns true if comparison_object is the same exact object, or comparison_object is of the same type and self has an ID and it is equal to comparison_object.id.

#clone

Identical to Ruby's clone method.

#connection_handler,
#dup

Duped objects have no id assigned and are treated as new records.

#encode_with

Populate coder with attributes about this record that should be serialized.

#eql?

Alias for Core#==.

#freeze

Clone and freeze the attributes hash such that associations are still accessible, even on destroyed records, but cloned models will not be frozen.

#hash

Delegates to id in order to allow two records of the same type and id to work with something like:

#init_with

Initialize an empty model object from coder.

#initialize

New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass a hash with key names matching the associated table column names).

#inspect

Returns the contents of the record as a nicely formatted string.

#pretty_print

Takes a PP and prettily prints this record to it, allowing you to get a nice result from pp record when pp is required.

#readonly!

Marks this record as read only.

#slice

Returns a hash of the given methods with their names as keys and returned values as values.

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveModel::AttributeMethods

Class Attribute Details

._attr_readonly (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/readonly_attributes.rb', line 6

class_attribute :_attr_readonly, instance_accessor: false

._attr_readonly?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/readonly_attributes.rb', line 6

class_attribute :_attr_readonly, instance_accessor: false

._reflections (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 10

class_attribute :_reflections, instance_writer: false

._reflections?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 10

class_attribute :_reflections, instance_writer: false

.aggregate_reflections (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 11

class_attribute :aggregate_reflections, instance_writer: false

.aggregate_reflections?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 11

class_attribute :aggregate_reflections, instance_writer: false

.attribute_type_decorations (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_decorators.rb', line 6

class_attribute :attribute_type_decorations, instance_accessor: false # :internal:

.attribute_type_decorations?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_decorators.rb', line 6

class_attribute :attribute_type_decorations, instance_accessor: false # :internal:

.cache_timestamp_format (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/integration.rb', line 14

class_attribute :cache_timestamp_format, :instance_writer => false

.cache_timestamp_format?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/integration.rb', line 14

class_attribute :cache_timestamp_format, :instance_writer => false

.configurations (rw)

Returns fully resolved configurations hash

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 51

def self.configurations
  @@configurations
end

.configurations=(config) (rw)

Contains the database configuration - as is typically stored in config/database.yml - as a ::Hash.

For example, the following database.yml…

development:
  adapter: sqlite3
  database: db/development.sqlite3

production:
  adapter: sqlite3
  database: db/production.sqlite3

…would result in .configurations to look like this:

{
   'development' => {
      'adapter'  => 'sqlite3',
      'database' => 'db/development.sqlite3'
   },
   'production' => {
      'adapter'  => 'sqlite3',
      'database' => 'db/production.sqlite3'
   }
}
[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 45

def self.configurations=(config)
  @@configurations = ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig.new(config).resolve
end

.connection_handler (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 100

def self.connection_handler
  ActiveRecord::RuntimeRegistry.connection_handler || default_connection_handler
end

.connection_handler=(handler) (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 104

def self.connection_handler=(handler)
  ActiveRecord::RuntimeRegistry.connection_handler = handler
end

.default_connection_handler (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 97

class_attribute :default_connection_handler, instance_writer: false

.default_connection_handler?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 97

class_attribute :default_connection_handler, instance_writer: false

.default_timezone (rw) Also known as: #default_timezone

Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling dates and times from the database. This is set to :utc by default.

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 59

mattr_accessor :default_timezone, instance_writer: false

.disable_implicit_join_references=(value) (writeonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 90

def self.disable_implicit_join_references=(value)
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
    Implicit join references were removed with Rails 4.1.
    Make sure to remove this configuration because it does nothing.
  MSG
end

.dump_schema_after_migration (rw) Also known as: #dump_schema_after_migration

Specify whether schema dump should happen at the end of the db:migrate rake task. This is true by default, which is useful for the development environment. This should ideally be false in the production environment where dumping schema is rarely needed.

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 85

mattr_accessor :dump_schema_after_migration, instance_writer: false

.find_by_statement_cache (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 98

class_attribute :find_by_statement_cache

.find_by_statement_cache?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 98

class_attribute :find_by_statement_cache

.local_stored_attributes (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/store.rb', line 70

attr_accessor :local_stored_attributes

.lock_optimistically (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 54

class_attribute :lock_optimistically, instance_writer: false

.lock_optimistically?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 54

class_attribute :lock_optimistically, instance_writer: false

.logger (rw) Also known as: #logger

Accepts a logger conforming to the interface of Log4r which is then passed on to any new database connections made and which can be retrieved on both a class and instance level by calling logger.

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 17

mattr_accessor :logger, instance_writer: false

.maintain_test_schema (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 88

mattr_accessor :maintain_test_schema, instance_accessor: false

.nested_attributes_options (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/nested_attributes.rb', line 13

class_attribute :nested_attributes_options, instance_writer: false

.nested_attributes_options?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/nested_attributes.rb', line 13

class_attribute :nested_attributes_options, instance_writer: false

.pluralize_table_names (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 50

class_attribute :pluralize_table_names, instance_writer: false

.pluralize_table_names?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 50

class_attribute :pluralize_table_names, instance_writer: false

.primary_key_prefix_type (rw) Also known as: #primary_key_prefix_type

Accessor for the prefix type that will be prepended to every primary key column name. The options are :table_name and :table_name_with_underscore. If the first is specified, the Product class will look for “productid” instead of “id” as the primary column. If the latter is specified, the Product class will look for “product_id” instead of “id”. Remember that this is a global setting for all Active Records.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 13

mattr_accessor :primary_key_prefix_type, instance_writer: false

.raise_in_transactional_callbacks (rw) Also known as: #raise_in_transactional_callbacks

[ GitHub ]

  
# File 'activerecord/lib/active_record/transactions.rb', line 23

mattr_accessor :raise_in_transactional_callbacks, instance_writer: false

.record_timestamps (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/timestamp.rb', line 34

class_attribute :record_timestamps

.record_timestamps?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/timestamp.rb', line 34

class_attribute :record_timestamps

.schema_format (rw) Also known as: #schema_format

Specifies the format to use when dumping the database schema with Rails' Rakefile. If :sql, the schema is dumped as (potentially database- specific) SQL statements. If :ruby, the schema is dumped as an Schema file which can be loaded into any database that supports migrations. Use :ruby if you want to have different database adapters for, e.g., your development and test environments.

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 70

mattr_accessor :schema_format, instance_writer: false

.schema_migrations_table_name (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 42

class_attribute :schema_migrations_table_name, instance_accessor: false

.schema_migrations_table_name?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 42

class_attribute :schema_migrations_table_name, instance_accessor: false

.store_full_sti_class (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/inheritance.rb', line 40

class_attribute :store_full_sti_class, instance_writer: false

.store_full_sti_class?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/inheritance.rb', line 40

class_attribute :store_full_sti_class, instance_writer: false

.table_name_prefix (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 25

class_attribute :table_name_prefix, instance_writer: false

.table_name_prefix?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 25

class_attribute :table_name_prefix, instance_writer: false

.table_name_suffix (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 36

class_attribute :table_name_suffix, instance_writer: false

.table_name_suffix?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 36

class_attribute :table_name_suffix, instance_writer: false

.timestamped_migrations (rw) Also known as: #timestamped_migrations

Specify whether or not to use timestamps for migration versions

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 76

mattr_accessor :timestamped_migrations, instance_writer: false

.user_provided_columns (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attributes.rb', line 8

class_attribute :user_provided_columns, instance_accessor: false # :internal:

.user_provided_columns?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attributes.rb', line 8

class_attribute :user_provided_columns, instance_accessor: false # :internal:

.user_provided_defaults (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attributes.rb', line 9

class_attribute :user_provided_defaults, instance_accessor: false # :internal:

.user_provided_defaults?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attributes.rb', line 9

class_attribute :user_provided_defaults, instance_accessor: false # :internal:

Class Method Details

.after_commit

.after_create

.after_destroy

.after_find

.after_initialize

.after_rollback

.after_save

.after_touch

.after_update

.around_create

.around_destroy

.around_save

.around_update

.before_create

.before_destroy

.before_save

.before_update

Instance Attribute Details

#_reflections (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 10

class_attribute :_reflections, instance_writer: false

#_reflections?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 10

class_attribute :_reflections, instance_writer: false

#aggregate_reflections (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 11

class_attribute :aggregate_reflections, instance_writer: false

#aggregate_reflections?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 11

class_attribute :aggregate_reflections, instance_writer: false

#cache_timestamp_format (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/integration.rb', line 14

class_attribute :cache_timestamp_format, :instance_writer => false

#cache_timestamp_format?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/integration.rb', line 14

class_attribute :cache_timestamp_format, :instance_writer => false

#column_for_attribute (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_methods.rb', line 23

delegate :column_for_attribute, to: :class

#default_connection_handler (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 97

class_attribute :default_connection_handler, instance_writer: false

#default_connection_handler?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 97

class_attribute :default_connection_handler, instance_writer: false

#default_timezone (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 59

mattr_accessor :default_timezone, instance_writer: false

#dump_schema_after_migration (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 85

mattr_accessor :dump_schema_after_migration, instance_writer: false

#find_by_statement_cache (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 98

class_attribute :find_by_statement_cache

#find_by_statement_cache?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 98

class_attribute :find_by_statement_cache

#lock_optimistically (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 54

class_attribute :lock_optimistically, instance_writer: false

#lock_optimistically?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 54

class_attribute :lock_optimistically, instance_writer: false

#logger (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 17

mattr_accessor :logger, instance_writer: false

#nested_attributes_options (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/nested_attributes.rb', line 13

class_attribute :nested_attributes_options, instance_writer: false

#nested_attributes_options?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/nested_attributes.rb', line 13

class_attribute :nested_attributes_options, instance_writer: false

#persistable_attribute_names (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attributes.rb', line 13

delegate :persistable_attribute_names, to: :class

#pluralize_table_names (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 50

class_attribute :pluralize_table_names, instance_writer: false

#pluralize_table_names?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 50

class_attribute :pluralize_table_names, instance_writer: false

#primary_key_prefix_type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 13

mattr_accessor :primary_key_prefix_type, instance_writer: false

#raise_in_transactional_callbacks (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/transactions.rb', line 23

mattr_accessor :raise_in_transactional_callbacks, instance_writer: false

#record_timestamps (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/timestamp.rb', line 34

class_attribute :record_timestamps

#record_timestamps?Boolean (rw)

[ GitHub ]

  
# File 'activerecord/lib/active_record/timestamp.rb', line 34

class_attribute :record_timestamps

#schema_format (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 70

mattr_accessor :schema_format, instance_writer: false

#store_full_sti_class (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/inheritance.rb', line 40

class_attribute :store_full_sti_class, instance_writer: false

#store_full_sti_class?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/inheritance.rb', line 40

class_attribute :store_full_sti_class, instance_writer: false

#table_name_prefix (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 25

class_attribute :table_name_prefix, instance_writer: false

#table_name_prefix?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 25

class_attribute :table_name_prefix, instance_writer: false

#table_name_suffix (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 36

class_attribute :table_name_suffix, instance_writer: false

#table_name_suffix?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 36

class_attribute :table_name_suffix, instance_writer: false

#timestamped_migrations (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/core.rb', line 76

mattr_accessor :timestamped_migrations, instance_writer: false

#type_for_attribute (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 55

delegate :type_for_attribute, to: :class