mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adds title and minor changes.
This commit is contained in:
parent
317a75bf58
commit
d8277804b2
5 changed files with 30 additions and 17 deletions
|
@ -29,7 +29,7 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
# Active Record Migrations
|
||||
# = Active Record Migrations
|
||||
#
|
||||
# Migrations can manage the evolution of a schema used by several physical
|
||||
# databases. It's a solution to the common problem of adding a field to make
|
||||
|
|
|
@ -4,11 +4,12 @@ require 'active_support/core_ext/kernel/singleton_class'
|
|||
require 'active_support/core_ext/object/blank'
|
||||
|
||||
module ActiveRecord
|
||||
# = Active Record Named Scopes
|
||||
module NamedScope
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
# Returns an anonymous scope.
|
||||
# Returns an anonymous \scope.
|
||||
#
|
||||
# posts = Post.scoped
|
||||
# posts.size # Fires "select count(*) from posts" and returns the count
|
||||
|
@ -18,10 +19,12 @@ module ActiveRecord
|
|||
# fruits = fruits.where(:colour => 'red') if options[:red_only]
|
||||
# fruits = fruits.limit(10) if limited?
|
||||
#
|
||||
# Anonymous \scopes tend to be useful when procedurally generating complex queries, where passing
|
||||
# intermediate values (scopes) around as first-class objects is convenient.
|
||||
# Anonymous scopes tend to be useful when procedurally generating complex
|
||||
# queries, where passing intermediate values (scopes) around as first-class
|
||||
# objects is convenient.
|
||||
#
|
||||
# You can define a scope that applies to all finders using ActiveRecord::Base.default_scope.
|
||||
# You can define a scope that applies to all finders using
|
||||
# ActiveRecord::Base.default_scope.
|
||||
def scoped(options = {}, &block)
|
||||
if options.present?
|
||||
relation = scoped.apply_finder_options(options)
|
||||
|
|
|
@ -15,7 +15,7 @@ module ActiveRecord
|
|||
self.nested_attributes_options = {}
|
||||
end
|
||||
|
||||
# == Nested Attributes
|
||||
# = Active Record Nested Attributes
|
||||
#
|
||||
# Nested attributes allow you to save attributes on associated records
|
||||
# through the parent. By default nested attribute updating is turned off,
|
||||
|
@ -25,6 +25,7 @@ module ActiveRecord
|
|||
#
|
||||
# The attribute writer is named after the association, which means that
|
||||
# in the following example, two new methods are added to your model:
|
||||
#
|
||||
# <tt>author_attributes=(attributes)</tt> and
|
||||
# <tt>pages_attributes=(attributes)</tt>.
|
||||
#
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'active_support/core_ext/class/attribute'
|
||||
|
||||
module ActiveRecord
|
||||
# = Active Record Observer
|
||||
#
|
||||
# Observer classes respond to lifecycle callbacks to implement trigger-like
|
||||
# behavior outside the original class. This is a great way to reduce the
|
||||
# clutter that normally comes when the model class is burdened with
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
module ActiveRecord
|
||||
# = Active Record Persistence
|
||||
module Persistence
|
||||
# Returns true if this object hasn't been saved yet -- that is, a record for the object doesn't exist yet; otherwise, returns false.
|
||||
# Returns true if this object hasn't been saved yet -- that is, a record
|
||||
# for the object doesn't exist in the data store yet; otherwise, returns false.
|
||||
def new_record?
|
||||
@new_record
|
||||
end
|
||||
|
@ -10,7 +12,8 @@ module ActiveRecord
|
|||
@destroyed
|
||||
end
|
||||
|
||||
# Returns if the record is persisted, i.e. it's not a new record and it was not destroyed.
|
||||
# Returns if the record is persisted, i.e. it's not a new record and it was
|
||||
# not destroyed.
|
||||
def persisted?
|
||||
!(new_record? || destroyed?)
|
||||
end
|
||||
|
@ -69,8 +72,8 @@ module ActiveRecord
|
|||
freeze
|
||||
end
|
||||
|
||||
# Deletes the record in the database and freezes this instance to reflect that no changes should
|
||||
# be made (since they can't be persisted).
|
||||
# Deletes the record in the database and freezes this instance to reflect
|
||||
# that no changes should be made (since they can't be persisted).
|
||||
def destroy
|
||||
if persisted?
|
||||
self.class.unscoped.where(self.class.arel_table[self.class.primary_key].eq(id)).delete_all
|
||||
|
@ -80,10 +83,13 @@ module ActiveRecord
|
|||
freeze
|
||||
end
|
||||
|
||||
# Returns an instance of the specified +klass+ with the attributes of the current record. This is mostly useful in relation to
|
||||
# single-table inheritance structures where you want a subclass to appear as the superclass. This can be used along with record
|
||||
# identification in Action Pack to allow, say, <tt>Client < Company</tt> to do something like render <tt>:partial => @client.becomes(Company)</tt>
|
||||
# to render that instance using the companies/company partial instead of clients/client.
|
||||
# Returns an instance of the specified +klass+ with the attributes of the
|
||||
# current record. This is mostly useful in relation to single-table
|
||||
# inheritance structures where you want a subclass to appear as the
|
||||
# superclass. This can be used along with record identification in
|
||||
# Action Pack to allow, say, <tt>Client < Company</tt> to do something
|
||||
# like render <tt>:partial => @client.becomes(Company)</tt> to render that
|
||||
# instance using the companies/company partial instead of clients/client.
|
||||
#
|
||||
# Note: The new instance will share a link to the same attributes as the original class. So any change to the attributes in either
|
||||
# instance will affect the other.
|
||||
|
@ -104,14 +110,15 @@ module ActiveRecord
|
|||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Updates all the attributes from the passed-in Hash and saves the record. If the object is invalid, the saving will
|
||||
# fail and false will be returned.
|
||||
# Updates all the attributes from the passed-in Hash and saves the record.
|
||||
# If the object is invalid, the saving will fail and false will be returned.
|
||||
def update_attributes(attributes)
|
||||
self.attributes = attributes
|
||||
save
|
||||
end
|
||||
|
||||
# Updates an object just like Base.update_attributes but calls save! instead of save so an exception is raised if the record is invalid.
|
||||
# Updates an object just like Base.update_attributes but calls save! instead
|
||||
# of save so an exception is raised if the record is invalid.
|
||||
def update_attributes!(attributes)
|
||||
self.attributes = attributes
|
||||
save!
|
||||
|
|
Loading…
Reference in a new issue