How to use the server/models/BaseModel.BelongsToOneRelation function in server

To help you get started, we’ve selected a few server 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 argos-ci / argos / src / server / models / Repository.js View on Github external
private: { type: 'boolean' },
      baselineBranch: { type: 'string' },
    },
  })

  static relationMappings = {
    builds: {
      relation: BaseModel.HasManyRelation,
      modelClass: 'Build',
      join: {
        from: 'repositories.id',
        to: 'builds.repositoryId',
      },
    },
    organization: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Organization',
      join: {
        from: 'repositories.organizationId',
        to: 'organizations.id',
      },
    },
    user: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'User',
      join: {
        from: 'repositories.userId',
        to: 'users.id',
      },
    },
  }
github argos-ci / argos / src / server / models / Repository.js View on Github external
modelClass: 'Build',
      join: {
        from: 'repositories.id',
        to: 'builds.repositoryId',
      },
    },
    organization: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Organization',
      join: {
        from: 'repositories.organizationId',
        to: 'organizations.id',
      },
    },
    user: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'User',
      join: {
        from: 'repositories.userId',
        to: 'users.id',
      },
    },
  }

  static getUsers(repositoryId) {
    return User.query()
      .select('users.*')
      .join(
        'user_repository_rights',
        'users.id',
        '=',
        'user_repository_rights.userId',
github argos-ci / argos / src / server / models / ScreenshotDiff.js View on Github external
maximum: 1,
      },
      validationStatus: {
        type: 'string',
        enum: [
          VALIDATION_STATUSES.unknown,
          VALIDATION_STATUSES.accepted,
          VALIDATION_STATUSES.rejected,
        ],
      },
    },
  })

  static relationMappings = {
    build: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Build',
      join: {
        from: 'screenshot_diffs.buildId',
        to: 'builds.id',
      },
    },
    baseScreenshot: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Screenshot',
      join: {
        from: 'screenshot_diffs.baseScreenshotId',
        to: 'screenshots.id',
      },
    },
    compareScreenshot: {
      relation: BaseModel.BelongsToOneRelation,
github argos-ci / argos / src / server / models / UserOrganizationRight.js View on Github external
userId: { type: 'string' },
      organizationId: { type: 'string' },
    },
  })

  static relationMappings = {
    user: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'User',
      join: {
        from: 'user_organization_rights.userId',
        to: 'users.id',
      },
    },
    organization: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Organization',
      join: {
        from: 'user_organization_rights.organizationId',
        to: 'organizations.id',
      },
    },
  }
}
github argos-ci / argos / src / server / models / Screenshot.js View on Github external
export default class Screenshot extends BaseModel {
  static tableName = 'screenshots'

  static jsonSchema = mergeSchemas(BaseModel.jsonSchema, {
    required: ['name', 's3Id', 'screenshotBucketId'],
    properties: {
      name: { type: 'string' },
      s3Id: { type: 'string' },
      screenshotBucketId: { type: 'string' },
    },
  })

  static relationMappings = {
    screenshotBucket: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'ScreenshotBucket',
      join: {
        from: 'screenshots.screenshotBucketId',
        to: 'screenshot_buckets.id',
      },
    },
  }
}
github argos-ci / argos / src / server / models / ScreenshotBucket.js View on Github external
branch: { type: 'string' },
      repositoryId: { type: 'string' },
    },
  })

  static relationMappings = {
    screenshots: {
      relation: BaseModel.HasManyRelation,
      modelClass: 'Screenshot',
      join: {
        from: 'screenshot_buckets.id',
        to: 'screenshots.screenshotBucketId',
      },
    },
    repository: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Repository',
      join: {
        from: 'screenshot_buckets.repositoryId',
        to: 'repositories.id',
      },
    },
  }
}
github argos-ci / argos / src / server / models / UserRepositoryRight.js View on Github external
userId: { type: 'string' },
      repositoryId: { type: 'string' },
    },
  })

  static relationMappings = {
    user: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'User',
      join: {
        from: 'user_repository_rights.userId',
        to: 'users.id',
      },
    },
    repository: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Repository',
      join: {
        from: 'user_repository_rights.repositoryId',
        to: 'repositories.id',
      },
    },
  }
}
github argos-ci / argos / src / server / models / Synchronization.js View on Github external
static tableName = 'synchronizations'

  static jsonSchema = mergeSchemas(BaseModel.jsonSchema, jobModelSchema, {
    required: ['userId', 'type'],
    properties: {
      userId: { type: 'string' },
      type: {
        type: 'string',
        enum: ['github'],
      },
    },
  })

  static relationMappings = {
    user: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'User',
      join: {
        from: 'synchronizations.userId',
        to: 'users.id',
      },
    },
  }
}
github argos-ci / argos / src / server / models / ScreenshotDiff.js View on Github external
modelClass: 'Build',
      join: {
        from: 'screenshot_diffs.buildId',
        to: 'builds.id',
      },
    },
    baseScreenshot: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Screenshot',
      join: {
        from: 'screenshot_diffs.baseScreenshotId',
        to: 'screenshots.id',
      },
    },
    compareScreenshot: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'Screenshot',
      join: {
        from: 'screenshot_diffs.compareScreenshotId',
        to: 'screenshots.id',
      },
    },
  }

  $parseDatabaseJson(json) {
    const newJson = super.$parseDatabaseJson(json)

    if (typeof newJson.score === 'string') {
      newJson.score = Number(newJson.score)
    }

    return newJson
github argos-ci / argos / src / server / models / Build.js View on Github external
static jsonSchema = mergeSchemas(BaseModel.jsonSchema, jobModelSchema, {
    required: ['compareScreenshotBucketId', 'repositoryId'],
    properties: {
      baseScreenshotBucketId: { types: ['string', null] },
      compareScreenshotBucketId: { type: 'string' },
      repositoryId: { type: 'string' },
      number: { type: 'integer' },
      externalId: { type: ['string', null] },
      batchCount: { type: ['integer', null] },
    },
  })

  static relationMappings = {
    baseScreenshotBucket: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'ScreenshotBucket',
      join: {
        from: 'builds.baseScreenshotBucketId',
        to: 'screenshot_buckets.id',
      },
    },
    compareScreenshotBucket: {
      relation: BaseModel.BelongsToOneRelation,
      modelClass: 'ScreenshotBucket',
      join: {
        from: 'builds.compareScreenshotBucketId',
        to: 'screenshot_buckets.id',
      },
    },
    repository: {
      relation: BaseModel.BelongsToOneRelation,