开发者

Question about FactoryGirl

开发者 https://www.devze.com 2023-02-18 01:06 出处:网络
I was reading through the documentation of Factory Girl and came across this code block. #The behavior of the association method varies depending on the build strategy used for the parent object.

I was reading through the documentation of Factory Girl and came across this code block.

#The behavior of the association method varies depending on the build strategy used for the parent object.

#Builds and saves a U开发者_开发百科ser 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

I'm new to Factory Girl, but shouldn't the first code example return true for new_record? I'm confused why it returns false if the post is built and saved.


new_record?() public
Returns true if this object hasn’t been saved yet — that is, a record for the object doesn’t exist yet; otherwise, returns false.
This method is deprecated on the latest stable version of Rails.

Edit:
Oops, looks like the link was broken. Fixed. new_record?

0

精彩评论

暂无评论...
验证码 换一张
取 消