How to use the objection.Model.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 feathersjs-ecosystem / feathers-objection / test / company.js View on Github external
object: { type: 'string' }
            }
          },
          'first.founder': { type: ['string', 'null'] }
        }
      },
      jsonArray: { type: ['array', 'null'] },
      jsonbObject: { type: ['object', 'null'] },
      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,
github damian-pastorini / reldens / packages / users / players-state-model.js View on Github external
static get relationMappings()
    {
        // to avoid require loop:
        const Players = require('./players-model');
        return {
            parent_player: {
                relation: Model.BelongsToOneRelation,
                modelClass: Players,
                join: {
                    from: 'players_state.player_id',
                    to: 'players.id'
                }
            }
        }
    }
github Vincit / objection.js / examples / koa-ts / models / Animal.ts View on Github external
static relationMappings = () => ({
    owner: {
      relation: Model.BelongsToOneRelation,
      // The related model.
      modelClass: Person,

      join: {
        from: 'animals.ownerId',
        to: 'persons.id'
      }
    }
  })
}
github strues / boldr / src / api / routes / token / token.model.js View on Github external
static get relationMappings() {
    return {
      tokens: {
        relation: Model.BelongsToOneRelation,
        modelClass: User,
        join: {
          from: 'token.user_id',
          to: 'user.id',
        },
      },
    };
  }
github SelfKeyFoundation / Identity-Wallet / src / main / wallet / wallet-setting.js View on Github external
static get relationMappings() {
		const Wallet = require('./wallet').default;
		return {
			wallet: {
				relation: Model.BelongsToOneRelation,
				modelClass: Wallet,
				join: {
					from: `${this.tableName}.walletId`,
					to: `${Wallet.tableName}.id`
				}
			}
		};
	}
github contentjet / contentjet-api / src / models / EntryTag.ts View on Github external
static get relationMappings(): RelationMappings {
    return {
      project: {
        relation: Model.BelongsToOneRelation,
        modelClass: `${__dirname}/Project`,
        join: {
          from: 'entryTag.projectId',
          to: 'project.id'
        }
      },
      entries: {
        relation: Model.ManyToManyRelation,
        modelClass: `${__dirname}/Entry`,
        join: {
          from: 'entryTag.id',
          through: {
            from: 'entry_entryTag.entryTagId',
            to: 'entry_entryTag.entryId'
          },
          to: 'entry.id'
github strues / boldr / src / api / routes / navigation / navigationLink.model.js View on Github external
static get relationMappings() {
    return {
      link: {
        relation: Model.BelongsToOneRelation,
        modelClass: Link,
        join: {
          from: 'navigation_link.link_id',
          to: 'link.id',
        },
      },
      navigation: {
        relation: Model.BelongsToOneRelation,
        modelClass: Navigation,
        join: {
          from: 'navigation_link.navigation_id',
          to: 'navigation.id',
        },
      },
    };
  }
github SelfKeyFoundation / Identity-Wallet / src / main / address-book / address-book.js View on Github external
static get relationMappings() {
		const Wallet = require('../wallet/wallet').default;
		return {
			wallet: {
				relation: Model.BelongsToOneRelation,
				modelClass: Wallet,
				join: {
					from: `${this.tableName}.walletId`,
					to: `${Wallet.tableName}.id`
				}
			}
		};
	}