开发者

belongs_to has_one associated record saving

开发者 https://www.devze.com 2023-01-09 02:35 出处:网络
If i have class User < ActiveRecord::Base has_many :books end . class Book < ActiveRecord::Base belongs_to :user

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

精彩评论

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

关注公众号