Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
190e270d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
190e270d
编写于
8月 09, 2010
作者:
N
Neeraj Singh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding more documentation for autosave option
上级
d87c57bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
14 deletion
+39
-14
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+2
-1
activerecord/lib/active_record/autosave_association.rb
activerecord/lib/active_record/autosave_association.rb
+37
-13
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
190e270d
...
...
@@ -311,7 +311,8 @@ def association_instance_set(name, association)
# You can set the :autosave option on a <tt>has_one</tt>, <tt>belongs_to</tt>,
# <tt>has_many</tt>, or <tt>has_and_belongs_to_many</tt> association. Setting it
# to +true+ will _always_ save the members, whereas setting it to +false+ will
# _never_ save the members.
# _never_ save the members. More details about :autosave option is available at
# autosave_association.rb .
#
# === One-to-one associations
#
...
...
activerecord/lib/active_record/autosave_association.rb
浏览文件 @
190e270d
...
...
@@ -18,6 +18,10 @@ module ActiveRecord
# Note that it also means that associations marked for destruction won't
# be destroyed directly. They will however still be marked for destruction.
#
# Do note that <tt>:autosave => false</tt> is not same as not declaring <tt>:autosave</tt>
# option. When <tt>:autosave</tt> option is not declared then it works in
# theoreticall <tt>:new_only</tt> mode. Look at has_many example discused below for details.
#
# === One-to-one Example
#
# class Post
...
...
@@ -57,27 +61,45 @@ module ActiveRecord
#
# === One-to-many Example
#
# When <tt>autosave</tt> is not declared then also children will get saved when parent is saved
# in certain conditions.
#
# Consider a Post model with many Comments:
#
# class Post
# has_many :comments
, :autosave => true
# has_many :comments
# :autosave option is no declared
# end
#
# Saving changes to the parent and its associated model can now be performed
# automatically _and_ atomically:
# post = Post.new(:title => 'ruby rocks')
# post.comments.build(:body => 'hello world')
# post.save #=> will save both post and comment
#
# post = Post.find(1)
# post.title # => "The current global position of migrating ducks"
# post.comments.first.body # => "Wow, awesome info thanks!"
# post.comments.last.body # => "Actually, your article should be named differently."
# post = Post.create(:title => 'ruby rocks')
# post.comments.build(:body => 'hello world')
# post.save #=> will save both post and comment
#
# post.title = "On the migration of ducks"
# post.comments.last.body = "Actually, your article should be named differently. [UPDATED]: You are right, thanks."
# post = Post.create(:title => 'ruby rocks')
# post.comments.create(:body => 'hello world')
# post.save #=> will save both post and comment
#
# post.save
# post.reload
# post.title # => "On the migration of ducks"
# post.comments.last.body # => "Actually, your article should be named differently. [UPDATED]: You are right, thanks."
# post = Post.create(:title => 'ruby rocks')
# post.comments.build(:body => 'hello world')
# post.comments[0].body = 'hi everyone'
# post.save #=> will save both post and comment and comment will have 'hi everyone'
#
# In the above cases even without <tt>autosave</tt> option children got updated.
#
# class Post
# has_many :comments, :autosave => true
# end
#
# <tt>:autosave</tt> declaration is required if an attempt is made to change an existing
# associatin in memory.
#
# post = Post.create(:title => 'ruby rocks')
# post.comments.create(:body => 'hello world')
# post.comments[0].body = 'hi everyone'
# post.save #=> will save both post and comment and comment will have 'hi everyone'
#
# Destroying one of the associated models members, as part of the parent's
# save action, is as simple as marking it for destruction:
...
...
@@ -125,6 +147,8 @@ module ActiveRecord
# post = Post.find(1)
# post.author.name = ''
# post.save(:validate => false) # => true
#
# Note that validation will be perfomend even if <tt>autosave</tt> option is not declared.
module
AutosaveAssociation
extend
ActiveSupport
::
Concern
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录