I have a user model that has many carts
class User < ActiveRecord::Base
has_many :carts
If I update a cart:
User.last.carts.last.time_purchased = Time.now
Is there a way I can save the whole user model? Now, if I call
User.last.save
The cart that I modified is not saved.
User.last.carts.last.save
Does save the cart.
Is there a way to save all updated attributes of a model?
Thanks
Saving a model will save any of its associations, but the reason this isn’t working for you is because you are re-fetching the
Usermodel instead of modifying and saving the same instance.Saving the user should also save the associated cart.