Comments (6)
Hi @krisfields, I'm sorry the README is not so clear (something similar is also open in #14).
I can't help you directly right now (I need to reproduce the case first). Maybe you can dig into this test and understand where your code is different?
from denormalizr.
Is it that it's not clear or that it's inaccurate?
I dug into that test and was not able to see how mine differed at all, other than in the expected result. In fact, I copied/pasted what I believe is the relevant code from that test and still get a different result. Here's what I tried:
import { normalize, Schema, arrayOf } from 'normalizr'
const articleSchema = new Schema('articles')
const userSchema = new Schema('users')
const collectionSchema = new Schema('collections')
articleSchema.define({
author: userSchema,
collections: arrayOf(collectionSchema),
})
collectionSchema.define({
curator: userSchema,
})
const article1 = {
id: 1,
title: 'Some Article',
author: {
id: 1,
name: 'Dan',
},
collections: [{
id: 1,
name: 'Dan',
}, {
id: 2,
name: 'Giampaolo',
}],
};
const article2 = {
id: 2,
title: 'Other Article',
author: {
id: 1,
name: 'Dan',
},
};
const article3 = {
id: 3,
title: 'Without author',
author: null,
};
const article4 = {
id: 4,
title: 'Some Article',
author: {
id: '',
name: 'Deleted',
},
collections: [{
id: '',
name: 'Deleted',
}],
};
const response = {
articles: [article1, article2, article3, article4],
}
const data = normalize(response, {
articles: arrayOf(articleSchema),
})
const articles = [
data.entities.articles['1'],
data.entities.articles['2'],
]
const denormalized = denormalize(articles, data.entities, arrayOf(articleSchema))
console.log("articles denormalized = ", denormalized)
And the output was not an Array and was not nested, but instead simply had the keys for each object that should have been nested, like before when copying from the README.
articles denormalized = Object {0: Object, 1: Object}
{0: {
author: 1,
collections: [{0:1}, {1:2}],
id: 1,
title: "Some Article"
},
1: {
author: 1,
id: 2,
title: "Other Article"
}}
So I'm really curious and confused as to where I may have went wrong.
from denormalizr.
@krisfields I'm curious as well.
Could you please check you are using the last version of denormalizr?
npm ls denormalizr
I've setup a small repo to test this case: https://github.com/gpbl/denormalizr-test
git clone https://github.com/gpbl/denormalizr-test.git
cd denormalizr-test
npm install
npm start
it logs:
Normalized data
{ entities:
{ articles:
{ '1': { id: 1, title: 'Some Article', author: 1, collections: [ 1, 2 ] },
'2': { id: 2, title: 'Other Article', author: 1 } },
users: { '1': { id: 1, name: 'Dan' } },
collections:
{ '1': { id: 1, name: 'Dan' },
'2': { id: 2, name: 'Giampaolo' } } },
result: { articles: [ 1, 2 ] } }
Denormalized:
[ { id: 1,
title: 'Some Article',
author: { id: 1, name: 'Dan' },
collections: [ { id: 1, name: 'Dan' }, { id: 2, name: 'Giampaolo' } ] },
{ id: 2, title: 'Other Article', author: { id: 1, name: 'Dan' } } ]
So it seems all correct to me (macOS, node v4.4.5).
from denormalizr.
Well, it works correctly for me when I run your test repo, but when I copy/paste the code from that repo's index.js file into my project, it no longer works correctly. The output is no longer an array, and no longer nested. I currently have no idea why but haven't had a lot of time to dig in yet. If you have any suggestions on what I might look into to determine what's going on, any help would be much appreciated.
mac, node v6.6.0
from denormalizr.
Ok, I guess I wasn't using the latest version of denormalizr. "npm upgrade normalizr --save" didn't actually upgrade it, which is what confused me. Now that I am using the latest version, everything works properly.
from denormalizr.
Awesome! Yes npm update
won't work for minor release < 1.0. I use npm-check for updating dependencies. It is safer :)
from denormalizr.
Related Issues (20)
- Support memoization HOT 11
- How does it handle circular schemas? HOT 2
- Update the README documentation HOT 4
- Typescript Support HOT 1
- Calling a function on each object after denormalization HOT 1
- Denormalised child objects are always empty HOT 2
- Feature request - support unpkg.com HOT 1
- Denormalizing setup problem HOT 2
- Lodash is getting duplicated in my build HOT 2
- Doesn't support using a function in getIdAttribute HOT 2
- Denormalizing a list of ids HOT 1
- Support normalizr 3.0 HOT 2
- denormalize isn't working with normalizr 3.2.1 HOT 2
- Related entities not correctly populated in latest version HOT 5
- Deprecating this module HOT 1
- Null should denormalize to null HOT 2
- Update readme? Normalizr denormalize doesn't handle recursive models, denormalizr still useful for that. HOT 3
- Maximum denormalization level, how to fail on missing entity? HOT 6
- why is the second argument to denormalize required? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from denormalizr.