ManyToMany relation's require loop
Hi, I have Base model
// models/base.js
const { Model } = require('objection')
class Base extends Model {
static get modelPaths() {
return [__dirname]
}
}
module.exports = Base
Card model
// models/card.js
const Base = require('./base')
const { pg: knex } = require('~root/db')
class Card extends Base {
static get tableName() {
return 'cards'
}
static get relationMappings() {
return {
partners: {
relation: Base.ManyToManyRelation,
modelClass: 'partner',
join: {
from: 'cards.id',
through: {
from: 'partner_card.card_id',
to: 'partner_card.partner_id',
},
to: 'partners.id',
},
},
}
}
$beforeUpdate() {
this.updatedAt = knex.fn.now()
}
}
module.exports = Card.bindKnex(knex)
Partner model
// models/partner.js
const Base = require('./base')
const { pg: knex } = require('~root/db')
class Partner extends Base {
static get tableName() {
return 'partners'
}
static get relationMappings() {
return {
cards: {
relation: Base.ManyToManyRelation,
modelClass: 'card',
join: {
from: 'partners.id',
through: {
from: 'partner_card.partner_id',
to: 'partner_card.card_id',
},
to: 'cards.id',
},
},
}
}
async $beforeUpdate() {
this.updatedAt = knex.fn.now()
}
}
module.exports = Partner.bindKnex(knex)
everything seems good but I'm getting this error

Objection: 2.1.3 Node.js: v12.16.1 OS: macOS Catalina 10.15.3
this is working when I'm writing like this modelClass: 'Card' or modelClass: 'Partner'

but when I'm uploading this to production server (Ubuntu) I'm getting this because my model names are lowercase

Yep, in linux files are case sensitive. You should just write the correct file name in modelClass.
Yep, in linux files are case sensitive. You should just write the correct file name in
modelClass.
@koskimas I'm sorry, but did you see my issue's main message? It's not working even the file name is correct.
@koskimas Please can you fix this bug? Still not working

@koskimas could reproduce this bug? I can't understand why are you ignoring this issue? Please help me to solve this problem
Try to simplify your code until you find where your require loop happens. It doesn't look like being related to objection.
Try to simplify your code until you find where your require loop happens. It doesn't look like being related to objection.
@elhigu why should I simplify my code if I'm using solution pattern described in the docs?
@koskimas can you help please? seems like relationMappings method isn't running lazily
in model file defined modeClass like this:
modelClass: join.path(__direname, 'path/to/model/transaction');
that's will be solve problem !