amplitude / redux-query

A library for managing network state in Redux
https://amplitude.github.io/redux-query
Other
1.1k stars 67 forks source link

Entities not stored by their id (breaks normalization) #46

Closed bstro closed 7 years ago

bstro commented 7 years ago

Hey, not sure where to look for the problem here. My query definitions look like

{
      idAttribute: entity => `${entity.id}`,
      url: query,
      update: Object.assign({}, {
        [resource_name_plural]: (prev, cur) => ({...prev, ...cur})
      }),
      options: {
        credentials: "include",
        headers: {
          Accept: "application/json",
        }
      }    
}

The problem is that when the entities are retrieved (which they are), they are stored in my Redux state by index, rather than by ID. Note the screenshot:

screen shot 2017-03-17 at 1 24 51 pm

If I had no need for denormalization, I could make this work. But when I denormalize them (with normalizr.denormalize), it attempts to look the entities up by ID, which breaks (each value for relational data loses its id and becomes undefined).

Any ideas?

bstro commented 7 years ago

nvm, I think this is because I need to normalize the data by ID myself in the transform function edit: confirmed :) that was totally it.