How to use the objection.BelongsToOneRelation function in objection

To help you get started, we’ve selected a few objection 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 Vincit / objection-find / tests / utils.js View on Github external
relation: objection.ManyToManyRelation,
      modelClass: Movie,
      join: {
        from: 'Person.id',
        through: {
          from: 'Person_Movie.actorId',
          to: 'Person_Movie.movieId'
        },
        to: 'Movie.id'
      }
    }
  };

  Animal.relationMappings = {
    owner: {
      relation: objection.BelongsToOneRelation,
      modelClass: Person,
      join: {
        from: 'Animal.ownerId',
        to: 'Person.id'
      }
    }
  }

  return {
    Person: Person,
    Animal: Animal,
    Movie: Movie
  };
}
github Vincit / objection-rest / tests / utils.js View on Github external
Person.tableName = 'Person';
  Animal.tableName = 'Animal';
  Movie.tableName = 'Movie';

  Person.knex(knex);
  Animal.knex(knex);
  Movie.knex(knex);

  Person.prototype.fullName = function () {
    return this.firstName + ' ' + this.lastName;
  };

  Person.relationMappings = {
    parent: {
      relation: objection.BelongsToOneRelation,
      modelClass: Person,
      join: {
        from: 'Person.pid',
        to: 'Person.id'
      }
    },

    children: {
      relation: objection.HasManyRelation,
      modelClass: Person,
      join: {
        from: 'Person.id',
        to: 'Person.pid'
      }
    },
github tandg-digital / objection-filter / test / utils.js View on Github external
static get relationMappings() {
      return {
        parent: {
          relation: objection.BelongsToOneRelation,
          modelClass: Person,
          join: {
            from: 'Person.pid',
            to: 'Person.id'
          }
        },

        pets: {
          relation: objection.HasManyRelation,
          modelClass: Animal,
          join: {
            from: 'Person.id',
            to: 'Animal.ownerId'
          }
        },
github Vincit / objection-find / tests / utils.js View on Github external
static get tableName() {
      return 'Movie';
    }
  }

  Person.knex(knex);
  Animal.knex(knex);
  Movie.knex(knex);

  Person.prototype.fullName = function() {
    return this.firstName + ' ' + this.lastName;
  };

  Person.relationMappings = {
    parent: {
      relation: objection.BelongsToOneRelation,
      modelClass: Person,
      join: {
        from: 'Person.pid',
        to: 'Person.id'
      }
    },

    pets: {
      relation: objection.HasManyRelation,
      modelClass: Animal,
      join: {
        from: 'Person.id',
        to: 'Animal.ownerId'
      }
    },
github Vincit / objection-graphql / lib / SchemaBuilder.js View on Github external
_relationField(modelData, relation) {
    if (relation instanceof objection.HasOneRelation
      || relation instanceof objection.BelongsToOneRelation
      || relation instanceof objection.HasOneThroughRelation) {
      return {
        type: this._typeForModel(modelData),
        args: _.omit(modelData.args, OMIT_FROM_RELATION_ARGS),
      };
    } else if (relation instanceof objection.HasManyRelation || relation instanceof objection.ManyToManyRelation) {
      return {
        type: new GraphQLList(this._typeForModel(modelData)),
        args: _.omit(modelData.args, OMIT_FROM_RELATION_ARGS),
      };
    }
    throw new Error(`relation type "${relation.constructor.name}" is not supported`);
  }