How to use the @orbit/data.RelationshipNotFound function in @orbit/data

To help you get started, we’ve selected a few @orbit/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orbitjs / orbit / packages / @orbit / record-cache / src / operation-processors / sync-schema-validation-processor.ts View on Github external
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,
github orbitjs / orbit / packages / @orbit / record-cache / src / operation-processors / async-schema-validation-processor.ts View on Github external
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,