Created
September 19, 2021 22:10
-
-
Save ap1969/24d599685d555b83b2c7f0fb74c823a0 to your computer and use it in GitHub Desktop.
Objection.js issue
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
// See https://vincit.github.io/objection.js/#models | |
// for more of what you can do here. | |
const { BaseModel } = require('./_basemodel'); | |
const Users = class extends BaseModel { | |
static get tableName() { | |
return "users"; | |
} | |
static get relationMappings() { | |
const Cohorts = new this.prototype.app.models.Cohorts(this.prototype.app); | |
const Tokens = new this.prototype.app.models.Tokens(this.prototype.app); | |
const ProfileFields = new this.prototype.app.models.ProfileFields( | |
this.prototype.app | |
); | |
return { | |
cohort: { | |
relation: Model.BelongsToOneRelation, | |
modelClass: Cohorts, | |
join: { | |
from: "users.cohortId", | |
to: "cohorts.id" | |
} | |
}, | |
tokens: { | |
relation: Model.HasManyRelation, | |
modelClass: Tokens, | |
join: { | |
from: "users.id", | |
to: "tokens.userId" | |
} | |
}, | |
profileFields: { | |
relation: Model.HasManyRelation, | |
modelClass: ProfileFields, | |
join: { | |
from: "users.id", | |
to: "profile_fields.userId" | |
} | |
} | |
}; | |
} | |
}; | |
module.exports = function(app) { | |
Users.prototype.app = app; | |
return Users; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment