How to use the objection.Model.HasManyRelation 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 feathersjs-ecosystem / feathers-objection / test / company.js View on Github external
jsonbArray: { type: ['array', 'null'] }
    }
  }

  // This object defines the relations to other models.
  static relationMappings = {
    ceos: {
      relation: Model.BelongsToOneRelation,
      modelClass: path.join(__dirname, '/people'),
      join: {
        from: 'companies.ceo',
        to: 'people.id'
      }
    },
    employees: {
      relation: Model.HasManyRelation,
      modelClass: path.join(__dirname, '/employee'),
      join: {
        from: 'companies.id',
        to: 'employees.companyId'
      }
    },
    clients: {
      relation: Model.HasManyRelation,
      modelClass: path.join(__dirname, '/client'),
      join: {
        from: 'companies.id',
        to: 'clients.companyId'
      }
    }
  }
}
github Vincit / objection-graphql / tests / setup / models / Person.js View on Github external
static get relationMappings() {
    const Review = require('./Review');
    const Movie = require('./Movie');

    return {
      reviews: {
        relation: Model.HasManyRelation,
        modelClass: Review,
        join: {
          from: 'Person.id',
          to: 'Review.reviewerId',
        },
      },

      movies: {
        relation: Model.ManyToManyRelation,
        modelClass: Movie,
        join: {
          from: 'Person.id',
          through: {
            from: 'Person_Movie.personId',
            to: 'Person_Movie.movieId',
          },
github SelfKeyFoundation / Identity-Wallet / src / main / identity / repository.js View on Github external
return {
			attributeTypes: {
				relation: Model.ManyToManyRelation,
				modelClass: IdAttributeType,
				join: {
					from: `${this.tableName}.id`,
					through: {
						from: 'repository_attribute_types.repositoryId',
						to: 'repository_attribute_types.attributeTypeId'
					},
					to: `${IdAttributeType.tableName}.id`
				}
			},
			uiSchemas: {
				relation: Model.HasManyRelation,
				modelClass: UiSchema,
				join: {
					from: `${this.tableName}.id`,
					to: `${UiSchema.tableName}.repositoryId`
				}
			}
		};
	}
github strues / boldr / packages / boldr-api / src / models / user.js View on Github external
modelClass: VerificationToken,
        join: {
          from: 'user.id',
          to: 'verification_token.user_id',
        },
      },
      resetToken: {
        relation: Model.HasOneRelation,
        modelClass: ResetToken,
        join: {
          from: 'user.id',
          to: 'reset_token.user_id',
        },
      },
      comments: {
        relation: Model.HasManyRelation,
        modelClass: Comment,
        join: {
          from: 'user.id',
          to: 'comment.comment_author_id',
        },
      },
    };
  }
github jmcdo29 / zeldaPlay / server / src / db / models / character_schema.ts View on Github external
from: `${Character.tableName}.id`,
        to: `${Weapon.tableName + Character.CHARID}`
      }
    },

    spells: {
      relation: Model.HasManyRelation,
      modelClass: Spell,
      join: {
        from: `${Character.tableName}.id`,
        to: `${Spell.tableName + Character.CHARID}`
      }
    },

    skills: {
      relation: Model.HasManyRelation,
      modelClass: Skill,
      join: {
        from: `${Character.tableName}.id`,
        to: `${Skill.tableName + Character.CHARID}`
      }
    },

    saves: {
      relation: Model.HasManyRelation,
      modelClass: Save,
      join: {
        from: `${Character.tableName}.id`,
        to: `${Save.tableName + Character.CHARID}`
      }
    },
github magmo / apps / packages / server / src / wallet / models / rule.ts View on Github external
import { Address } from 'fmg-core';
import { Model } from 'objection';
import AllocatorChannel from './allocatorChannel';

export default class Rule extends Model {
  static tableName = 'rules';
  static idColumn = 'address';

  static relationMappings = {
    channels: {
      relation: Model.HasManyRelation,
      modelClass: AllocatorChannel,
      join: {
        to: 'allocator_channels.rule_id',
        from: 'rules.id',
      },
    },
  };
  readonly id!: string;
  readonly address!: Address;
  readonly name!: string;
}
github damian-pastorini / reldens / packages / rooms / model.js View on Github external
static get relationMappings()
    {
        const RoomsChangePoints = require('./change-points-model');
        const RoomsReturnPoints = require('./return-points-model');
        return {
            rooms_change_points: {
                relation: Model.HasManyRelation,
                modelClass: RoomsChangePoints,
                join: {
                    from: 'rooms.id',
                    to: 'rooms_change_points.room_id'
                }
            },
            rooms_return_points: {
                relation: Model.HasManyRelation,
                modelClass: RoomsReturnPoints,
                join: {
                    from: 'rooms.id',
                    to: 'rooms_return_points.room_id'
                }
            },
            next_room: {
                relation: Model.BelongsToOneRelation,
github magmo / apps / packages / server / src / wallet / models / allocatorChannelCommitment.ts View on Github external
import AllocatorChannel from './allocatorChannel';

export default class AllocatorChannelCommitment extends Model {
  static tableName = 'allocator_channel_commitments';

  static relationMappings = {
    allocatorChannel: {
      relation: Model.BelongsToOneRelation,
      modelClass: `${__dirname}/allocatorChannel`,
      join: {
        from: 'allocator_channel_commitments.allocator_channel_id',
        to: 'allocator_channels.id',
      },
    },
    allocations: {
      relation: Model.HasManyRelation,
      modelClass: `${__dirname}/allocation`,
      join: {
        from: 'allocator_channel_commitments.id',
        to: 'allocations.allocator_channel_commitment_id',
      },
    },
  };

  static get columnNameMappers() {
    return snakeCaseMappers();
  }

  readonly id!: number;
  allocatorChannel!: AllocatorChannel;
  allocatorChannelId!: number;
  turnNumber!: Uint32;
github damian-pastorini / reldens / packages / chat / server / model.js View on Github external
static get relationMappings()
    {
        const RoomsModel = require('../../rooms/server/model');
        const PlayersModel = require('../../users/server/players-model');
        return {
            chat_room: {
                relation: Model.HasManyRelation,
                modelClass: RoomsModel,
                join: {
                    from: 'room.id',
                    to: 'rooms.id'
                }
            },
            chat_player_id: {
                relation: Model.HasManyRelation,
                modelClass: PlayersModel,
                join: {
                    from: 'player_id',
                    to: 'players.id'
                }
            },
            chat_private_player_id: {
                relation: Model.HasManyRelation,
github GraphqlBA / codenames-gql / server / models / Game.js View on Github external
import { Model } from 'objection'
import Card from './Card'

export default class Game extends Model {
  static tableName = 'games'

  static relationMappings = {
    cards: {
      relation: Model.HasManyRelation,
      modelClass: Card,
      join: {
        from: 'games.id',
        to: 'cards.game_id'
      }
    }
  }
}