Created
August 2, 2019 08:47
-
-
Save gemmadlou/24acec10b47d4fd25090f161797df4da to your computer and use it in GitHub Desktop.
Objection Js: Has One Relation (aka Many to one)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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