We have a scenario when an embedded record of an embedded record returns null.
The relationship chain looks like this: userProfile
--belongsTo--> organisation
--hasOne (i.e. belongsTo)--> jurisdiction
.
However, when fetching all userProfile
records, the jurisdiction remains unpopulated.
So far, the respective serializers and models look like this:
UserProfile
Model
organisation: belongsTo('organisation', { async: false }),
Serializer
attrs: {
'organisation': { embedded: 'always' },
...
},
Organisation
Model
userProfile: hasMany('userProfile', { async: false }),
jurisdiction: belongsTo('jurisdiction', { async: false }),
Serializer
attrs: {
...
'jurisdiction': { embedded: 'always' },
},
Jurisdiction
Model
organisation: belongsTo('organisation', { async: false }),
Serializer
attrs: {
...
area: { key: 'jurisdictionArea' },
name: { key: 'jurisdictionName' },
},
I believe the issue might be that this part of the API doesn't appear to conform to the the JSON API spec, as an example userProfile
response might look like:
...
organisation: {
jurisdictionArea: "TAU"
jurisdictionId: "82cfda0b-3180-41cf-b0fa-b1193655bc0b"
organisationId: "960d4ec2-bc90-11e8-a355-529269fb1459"
}
I think this might be able to be resolved via the normalizeResponse
or serializeBelongsTo
methods in the organisation
serializer, however, so far my attempts have not been successful. Any advice on how to resolve this would be much appeaciated.
Aucun commentaire:
Enregistrer un commentaire