rails - how to refresh an association after a save

后端 未结 3 1387
醉酒成梦
醉酒成梦 2021-01-03 19:19

I have a category with a list of items. The items have a position and the category has a relationship has_many :items, :order => \"position\". When a user updates a position

3条回答
  •  时光说笑
    2021-01-03 19:56

    For single-item associations:

    book.reload_author
    

    For other associations:

    author.books.reload
    

    http://guides.rubyonrails.org/association_basics.html#controlling-caching


    In older versions of rails, before Rails 5, you could pass true to an association method as the first parameter to make it reload: author.books(true).

提交回复
热议问题