store_model icon indicating copy to clipboard operation
store_model copied to clipboard

accepts_nested_attributes_for allow partial updates

Open acetinick opened this issue 2 years ago • 2 comments

When using accepts_nested_attributes_for on models the JSON objects gets overidden completely with the next update that happens on the model.

eg. if you have two attributes in the store, and update each atrtibute using two separate forms, it will override the whole store with only the new attribute.

To fix this I have a override in my model, but feel it should be a default for the library.

image

acetinick avatar Oct 16 '23 06:10 acetinick

Hey hey, good call! Wanna try to make a PR to make it work on the gem level? 🙂

DmitryTsepelev avatar Oct 17 '23 20:10 DmitryTsepelev

Good call! At the same time, what do we do if we indeed want to override the whole hash with the new hash, e.g. delete some of the attributes? I was thinking about an attribute _partial that'd be passed with the hash, so it could indicate only partial update, but I don't like interfering with the original data.

alexeevit avatar Jan 31 '24 11:01 alexeevit

Rails achieves this by

  1. presence or absence of an id , and
  2. an update_only flag.

https://api.rubyonrails.org/v7.1.3.4/classes/ActiveRecord/NestedAttributes/ClassMethods.html

An implementation like that would keep with active record api expectations.

briandunn avatar Aug 05 '24 12:08 briandunn

Likely gonna be addressed by #180

DmitryTsepelev avatar Aug 24 '24 08:08 DmitryTsepelev