Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
extractRelationship(relationshipModelName, relationshipHash) {
if (isDocumentReference(relationshipHash)) {
const path = buildPathFromRef(relationshipHash);
const pathNodes = path.split('/');
const belongsToId = pathNodes[pathNodes.length - 1];
return { id: belongsToId, type: relationshipModelName };
}
return null;
},
modelClass.eachRelationship((name, descriptor) => {
if (descriptor.kind === 'belongsTo') {
if (
Object.prototype.hasOwnProperty.call(resourceHash, name)
&& isDocumentReference(resourceHash[name])
) {
const path = buildPathFromRef(resourceHash[name]);
links[name] = path;
}
} else {
const cardinality = modelClass.determineRelationshipType(descriptor, this.store);
let hasManyPath;
if (cardinality === 'manyToOne') {
hasManyPath = buildCollectionName(descriptor.type);
} else {
const collectionName = buildCollectionName(modelClass.modelName);
const docId = resourceHash.id;
hasManyPath = `${collectionName}/${docId}/${name}`;
}