开发者

belongs_to has_one associated record saving

If i have

class User < ActiveRecord::Base
  has_many :books
end

.

class Book < ActiveRecord::Base
  belongs_to :user
en开发者_开发知识库d

Question: When i save an instance of Book, will it call save on its associated User as well?

In my code base im finding that when i call @somebook.save, 'User's after_save callbacks are being executed.


Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜