输入:
provider: {
id: 1,
name: 'abc',
npi: 1234,
credentials: [{
id: 1,
description: 'abc'
}],
specialties: [{
id: 1,
description: 'abc'
}],
supervisingPhysician: {
id: 2,
name: 'xyz',
npi: 56789,
credentials: [{
id: 1,
description: 'abc'
}],
}
}
架构
import { schema } from 'normalizr';
import _ from 'lodash';
let specialtySchema = new schema.Entity('specialties');
export const providerSchema = new schema.Entity('provider', {
specialties: [specialtySchema], primarySpecialty: specialtySchema
});
预期输出:(类似)
entities: { providers: { "1" : {..., supervisingPhysician: 2, specialties: 1},
"2" : {..., specialties: 1}
},
specialties: {"1" : {...specialty object}
}
在我的示例中,我的根提供者对象和嵌套的 supervisingPhysician 对象都是相同类型的对象(提供者)。
如何定义模式,以便我可以同时规范化 root 和 supervisingPhysician。
谢谢你看这个。