I'm creating a simple example to learn the redux-orm library. I've set up my reducer as below and everything seems to work great.
const orm = new ORM();
orm.register(Profile, User);
export function reducer(state, {type, payload}) {
const session = orm.session(state || orm.getEmptyState());
switch(type) {
case 'CREATE_USER':
session.User.create(payload)
break;
case 'CREATE_PROFILE':
session.Profile.create(payload)
break;
}
return session.state;
}
I'm following the example to create a simple selector, that gets the entire list of users in the DB:
export const getUsers = createSelector(orm, session => {
return session.User.map(user => {
return user.ref
});
});
However, upon using the selector, Chrome gives me an error:
ERROR TypeError: session.User.map is not a function
Am I missing something? Or is this a bug with the library?
You need to use either
toModelArrayortoRefArray. The equivalent code to what you seem to be going for in your example (getting the refs for eachUser) would be:If you need to do further processing, like getting relations or refining to only a subset of properties, use
toModelArrayandmapthrough it as you would a normal array.