Open cristina-cowboy opened 2 years ago
I am trying to create/ update a record with associated data and also with a specific field only for the the create operation. I am running into the following situation:
params = { name: 'a', nested_resource: { name: 'b' } } record = MyRecord.new(params) record.special_attribute = 'create' record.upsert
In this case the nested_resource gets updated if the record gets updated, but the special_attribute gets set as well.
nested_resource
special_attribute
If I want to keep the special_attribute only on create and switch to something like this:
record = MyRecord.new(params) record.special_attribute = 'this' record.upsert(attributes: params.keys)
Then the nested resource doesn't get updated when the record gets updated (a new associated record is created instead).
Is there a way to specify nested attributes just for update operation?
I triedrecord.update(params) and it doesn't work for me.
record.update(params)
I am trying to create/ update a record with associated data and also with a specific field only for the the create operation. I am running into the following situation:
In this case the
nested_resource
gets updated if the record gets updated, but thespecial_attribute
gets set as well.If I want to keep the
special_attribute
only on create and switch to something like this:Then the nested resource doesn't get updated when the record gets updated (a new associated record is created instead).
Is there a way to specify nested attributes just for update operation?
I tried
record.update(params)
and it doesn't work for me.