Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected _validateRelationship(
record: Record,
relationship: string,
relatedRecord: RecordIdentity
) {
const modelSchema = this._getModelSchema(record.type);
const relationshipDef =
modelSchema.relationships && modelSchema.relationships[relationship];
if (relationshipDef === undefined) {
throw new RelationshipNotFound(relationship, record.type);
}
const type = relationshipDef.kind
? relationshipDef.type
: relationshipDef.model;
if (Array.isArray(type)) {
if (!type.includes(relatedRecord.type)) {
throw new IncorrectRelatedRecordType(
relatedRecord.type,
relationship,
record.type
);
}
} else if (typeof type === 'string') {
if (type !== relatedRecord.type) {
throw new IncorrectRelatedRecordType(
relatedRecord.type,
protected _validateRelationship(
record: Record,
relationship: string,
relatedRecord: RecordIdentity
) {
const modelSchema = this._getModelSchema(record.type);
const relationshipDef =
modelSchema.relationships && modelSchema.relationships[relationship];
if (relationshipDef === undefined) {
throw new RelationshipNotFound(relationship, record.type);
}
const type = relationshipDef.kind
? relationshipDef.type
: relationshipDef.model;
if (Array.isArray(type)) {
if (!type.includes(relatedRecord.type)) {
throw new IncorrectRelatedRecordType(
relatedRecord.type,
relationship,
record.type
);
}
} else if (typeof type === 'string') {
if (type !== relatedRecord.type) {
throw new IncorrectRelatedRecordType(
relatedRecord.type,