2
我正在閱讀documentation of Factory Girl並遇到此代碼塊。關於FactoryGirl的問題
#The behavior of the association method varies depending on the build strategy used for the parent object.
#Builds and saves a User and a Post
post = FactoryGirl.create(:post)
post.new_record? # => false
post.author.new_record # => false
# Builds and saves a User, and then builds but does not save a Post
post = FactoryGirl.build(:post)
post.new_record? # => true
post.author.new_record # => false
我是新工廠女孩,但應該不是第一個代碼示例new_record返回true?我很困惑,爲什麼它會返回false,如果這個帖子是建立和保存的。
啊。我懂了。這是一個相當混亂的術語,所以我很高興它已被棄用。我想他們還沒有到處去更新文檔。 http://api.rubyonrails.org/classes/ActiveRecord/Base.html – picardo 2011-03-19 15:03:33