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

Is it possible to merge values into a field instead of overwriting it? #1708

Closed
eunicode opened this issue Feb 27, 2023 · 0 comments
Closed

Comments

@eunicode
Copy link

eunicode commented Feb 27, 2023

If we have a model Author that has an Authored Books field that can have links to multiple Book entries, is it possible to use update(), or another method, to add a book link to the Authored Books field, rather than overwriting it?

For example, if we have the following, can we add a book to the list?

Author: Dr. Seuss
Authored Books: ["Green Eggs and Ham", "The Cat in the Hat"] 

With update(), it overwrites the field:

// Simplified code 
cmaClient.entry.update(
  { entryId: 1 },
  {
    fields: {
      authoredBooks: { ["How the Grinch Stole Christmas"] }
  }  
)
  
// Results in 
Authored Books: ["How the Grinch Stole Christmas"]
instead of
Authored Books: ["Green Eggs and Ham", "The Cat in the Hat", "How the Grinch Stole Christmas"] 

It seems I could use get() in combination with update(), and use the spread operator, but is it possible to do it with one API call?

EDIT: This issue is similar to another issue I opened, so closing this one.

@eunicode eunicode closed this as completed Mar 1, 2023
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