question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge records in update

See original GitHub issue

Re: updateStart and updateSuccess. The API says the updated records are ‘merged with the current state’. I took this to mean that the results of the update operation are merged with the current record, i.e. if the application state for the resource looks like

[0: {id: 'exampleId', width: 10}]

and we dispatch an action thus:

updateStart({id: 'exampleId', height: 20})

the updated state would look like:

[0: {id: 'exampleId', width: 10, height: 20}]

As it is, though, the width property is lost, and I’m getting

[0: {id: 'exampleId', height: 10}]

Is this expected behaviour, that is to say, update operations update records in the current state, using the given key, but overwrite the record contents, rather than merging them? Or am I using the library incorrectly? I’ll submit code to reproduce if needed.

Thanks for your help, this library looks like just what I need!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
GuillaumeJasmincommented, May 25, 2017

Is there going to be a future update for this ? Maybe an option like this: updateSuccess(item, {merge: true}) ?

1reaction
jsherbertcommented, Oct 14, 2016

Thanks for your reply!

I wonder whether this is desirable behaviour. In order to dispatch updateStart or updateSuccess, the user must have merged their desired changes with the entire preexisting record, or lose their existing model data.

This action almost always necessitates a call to a selector, because it’s unlikely that the part of the app making the update call knows about the entire model. As in the example above, a form that edits width but not height will need to pull the model beforehand and merge before calling updateStart or updateSuccess:

/**
 * @param {{id: number, width: string}} data
 */
const onSubmit = data => {
  const originalRecord = findById(data.id)
  const newRecord = originalRecord.merge(data)
  store.dispatch(updateStart(newRecord))
}

Whereas if we were merging in the library, this operation would look like

/**
 * @param {{id: number, width: string}} data
 */
const onSubmit = data => {
  store.dispatch(updateStart(data))
}

I’m probably missing something, but is there a use case in which not merging (the current behaviour) is necessary or desirable? If not, I’d be happy to submit a PR either changing this behaviour or making it configurable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use MERGE for Updating records when ID is repeating?
The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than...
Read more >
Merging with multiple update data sets - IBM
In order to merge a master and multiple update data sets, all data sets must be sorted and contain no duplicate records where...
Read more >
Criteria for new, update, delete and merged records
Criteria for new, update, delete and merged records ... Transaction types are relevant to knowledge base, query collections, and WorldCat updates.
Read more >
SQL Server MERGE to insert, update and delete at the same ...
The MERGE statement basically works as separate INSERT, UPDATE, and DELETE statements all within the same statement. You specify a "Source" ...
Read more >
Understanding the SQL MERGE statement - SQLShack
The MERGE statement in SQL is a very popular clause that can handle inserts, updates, and deletes all in a single transaction without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found