Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const idField = relatedModel.fields.id;
if (!idField) {
throw new Error(
`ID_FIELD_NOT_FOUND ${modelName}/${relationName}/${relatedModelName}`
);
}
relation.type = idField.type;
// Create inverse relation, if needed
const { inverse } = relation;
if (inverse !== false) {
let inverseRelation =
inverse == null || inverse === true
? {} // inverse shorthand
: omit(clone(inverse), ['name']);
inverseRelation = addDefaults(inverseRelation, {
model: modelName,
isPlural: true,
isInverse: true,
inverseName: relationName,
});
const idField2 = models[modelName].fields.id;
inverseRelation.type = idField2 ? idField2.type : undefined;
const { isPlural: isInversePlural } = inverseRelation;
const inverseName =
(inverse && inverse.name) ||
(isInversePlural ? pluralize(modelName) : modelName);
const inverseFkName = getFkName(
inverseName,
isInversePlural != null ? isInversePlural : true
);
const configure = (newConfig: $Shape) => {
if (!_config) {
_config = clone(newConfig);
return;
}
_config = (merge(_config, newConfig): any);
};