Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Created August 2, 2019 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gemmadlou/24acec10b47d4fd25090f161797df4da to your computer and use it in GitHub Desktop.
Save gemmadlou/24acec10b47d4fd25090f161797df4da to your computer and use it in GitHub Desktop.
Objection Js: Has One Relation (aka Many to one)
const {
Model
} = require('objection');
const Knex = require('knex');
const config = require('../config')
const Authority = require('./authority')
class Licence extends Model {
static get tableName() {
return 'licence';
}
static get relationMappings() {
return {
authority: {
relation: Model.HasOneRelation,
modelClass: Authority,
join: {
from: 'licence.authority_code',
to: 'authority.code'
}
}
}
}
}
Licence.knex(Knex(config.databases.licence))
module.exports = Licence;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment