Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying upsert attributes for associated data #119

Open
cristina-cowboy opened this issue Oct 11, 2021 · 0 comments
Open

Specifying upsert attributes for associated data #119

cristina-cowboy opened this issue Oct 11, 2021 · 0 comments

Comments

@cristina-cowboy
Copy link

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant