提交 95546d49 编写于 作者: V Vijay Dev

Merge branch 'master' of github.com:rails/docrails

......@@ -49,7 +49,7 @@ module ActiveModel
# puts 'block successfully called.'
# end
#
# You can choose not to have all three callbacks by passing a hash to the
# You can choose to have only specific callbacks by passing a hash to the
# +define_model_callbacks+ method.
#
# define_model_callbacks :create, only: [:after, :before]
......
......@@ -118,7 +118,7 @@ module Dirty
attribute_method_affix prefix: 'restore_', suffix: '!'
end
# Returns +true+ if any attribute have unsaved changes, +false+ otherwise.
# Returns +true+ if any of the attributes have unsaved changes, +false+ otherwise.
#
# person.changed? # => false
# person.name = 'bob'
......@@ -166,7 +166,7 @@ def changed_attributes
@changed_attributes ||= ActiveSupport::HashWithIndifferentAccess.new
end
# Handle <tt>*_changed?</tt> for +method_missing+.
# Handles <tt>*_changed?</tt> for +method_missing+.
def attribute_changed?(attr, options = {}) #:nodoc:
result = changes_include?(attr)
result &&= options[:to] == __send__(attr) if options.key?(:to)
......@@ -174,7 +174,7 @@ def attribute_changed?(attr, options = {}) #:nodoc:
result
end
# Handle <tt>*_was</tt> for +method_missing+.
# Handles <tt>*_was</tt> for +method_missing+.
def attribute_was(attr) # :nodoc:
attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
end
......@@ -186,6 +186,7 @@ def restore_attributes(attributes = changed)
private
# Returns +true+ if attr_name is changed, +false+ otherwise.
def changes_include?(attr_name)
attributes_changed_by_setter.include?(attr_name)
end
......@@ -197,18 +198,18 @@ def changes_applied # :doc:
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
# Clear all dirty data: current changes and previous changes.
# Clears all dirty data: current changes and previous changes.
def clear_changes_information # :doc:
@previously_changed = ActiveSupport::HashWithIndifferentAccess.new
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
# Handle <tt>*_change</tt> for +method_missing+.
# Handles <tt>*_change</tt> for +method_missing+.
def attribute_change(attr)
[changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
end
# Handle <tt>*_will_change!</tt> for +method_missing+.
# Handles <tt>*_will_change!</tt> for +method_missing+.
def attribute_will_change!(attr)
return if attribute_changed?(attr)
......@@ -221,7 +222,7 @@ def attribute_will_change!(attr)
set_attribute_was(attr, value)
end
# Handle <tt>restore_*!</tt> for +method_missing+.
# Handles <tt>restore_*!</tt> for +method_missing+.
def restore_attribute!(attr)
if attribute_changed?(attr)
__send__("#{attr}=", changed_attributes[attr])
......@@ -230,7 +231,7 @@ def restore_attribute!(attr)
end
# This is necessary because `changed_attributes` might be overridden in
# other implemntations (e.g. in `ActiveRecord`)
# other implementations (e.g. in `ActiveRecord`)
alias_method :attributes_changed_by_setter, :changed_attributes # :nodoc:
# Force an attribute to have a particular "before" value
......
......@@ -1438,7 +1438,7 @@ def has_one(name, scope = nil, options = {})
# when you access the associated object.
#
# Scope examples:
# belongs_to :user, -> { where(id: 2) }
# belongs_to :firm, -> { where(id: 2) }
# belongs_to :user, -> { joins(:friends) }
# belongs_to :level, ->(level) { where("game_level > ?", level.current) }
#
......@@ -1516,9 +1516,9 @@ def has_one(name, scope = nil, options = {})
# belongs_to :attachable, polymorphic: true
# belongs_to :project, readonly: true
# belongs_to :post, counter_cache: true
# belongs_to :company, touch: true
# belongs_to :comment, touch: true
# belongs_to :company, touch: :employees_last_updated_at
# belongs_to :company, required: true
# belongs_to :user, required: true
def belongs_to(name, scope = nil, options = {})
reflection = Builder::BelongsTo.build(self, name, scope, options)
Reflection.add_reflection self, name, reflection
......
......@@ -741,8 +741,8 @@ def reset_callbacks(name)
#
# * <tt>:skip_after_callbacks_if_terminated</tt> - Determines if after
# callbacks should be terminated by the <tt>:terminator</tt> option. By
# default after callbacks executed no matter if callback chain was
# terminated or not. Option makes sense only when <tt>:terminator</tt>
# default after callbacks are executed no matter if callback chain was
# terminated or not. This option makes sense only when <tt>:terminator</tt>
# option is specified.
#
# * <tt>:scope</tt> - Indicates which methods should be executed when an
......
......@@ -171,7 +171,7 @@ class CreateCustomers < ActiveRecord::Migration
end
create_table :orders do |t|
t.belongs_to :customer, index:true
t.belongs_to :customer, index: true
t.datetime :order_date
t.timestamps null: false
end
......@@ -691,7 +691,7 @@ c.first_name = 'Manny'
c.first_name == o.customer.first_name # => false
```
This happens because c and o.customer are two different in-memory representations of the same data, and neither one is automatically refreshed from changes to the other. Active Record provides the `:inverse_of` option so that you can inform it of these relations:
This happens because `c` and `o.customer` are two different in-memory representations of the same data, and neither one is automatically refreshed from changes to the other. Active Record provides the `:inverse_of` option so that you can inform it of these relations:
```ruby
class Customer < ActiveRecord::Base
......@@ -726,10 +726,10 @@ Most associations with standard names will be supported. However, associations
that contain the following options will not have their inverses set
automatically:
* :conditions
* :through
* :polymorphic
* :foreign_key
* `:conditions`
* `:through`
* `:polymorphic`
* `:foreign_key`
Detailed Association Reference
------------------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册