0

I am trying to update many entities using adapter.updateMany().

I have Groups entity that looks like this (There are multiple groups with multiple children):

enter image description here

{
  "id": 1,
  "children": [
    {
      "id": 222,
      "width": null,
      "height": null,
      ...multipleOtherProperties
    }
  ]
}

I am trying to update child width and height inside the group with:

const groups = [
  {
    "id": 0,
    "children": [
      {
        "id": 222,
        "groupId": 0,
        "width": 400,
        "height": 368.28125
      }
    ]
  }
]

But when I use:

on(GroupsActions.updateGroups, (state, { groups }) =>
  adapter.updateMany(groups, state)
)

Nothing is happening and when I change updateMany to upsertMany

on(GroupsActions.updateGroups, (state, { groups }) =>
  adapter.upsertMany(groups, state)
)

Children are replaced and I am losing all the properties which are not part of the update. How to update the properties of children without removing all other properties?

Any help would be appreciated. Thank you

pjpscriv
  • 866
  • 11
  • 20
omygoodness
  • 335
  • 3
  • 18
  • I think the adapter does not provide such functionality. You would have to alter the state manually – Deitsch Dec 21 '21 at 15:20
  • In the meantime, I was trying to create solution and I tested `adapter.updateOne` with partial changes like this: `adapter.updateOne({id, changes: { children: changes }}, state)` and it works like expected but I cant translate this into `updateMany` – omygoodness Dec 21 '21 at 15:24

0 Answers0