Closed MrDHat closed 7 years ago
Try updating your models
property value to:
models: [`${__dirname}/models/*.js`],
Or if your models are in separate sub folders e.g. models/user/index.js
, then try this:
models: [`${__dirname}/models/**/*.js`],
If the above doesn't work, can you share your folder structure?
Ah, that worked. Thanks!
I solved with:
models: ['**/sequelize/models/**.js'],
Hi, I am facing the same issue here.
Here is my code:
const sequelize = new Sequelize('mydatabasename', 'postgres', 'root', {
host: 'localhost',
port: '5432',
dialect: 'postgres'
})
await server.register([
{
plugin: HapiSequelize,
options: [
{
name: 'db', // identifier
models: [__dirname + '/models/**/*.js'], // paths/globs to model files
// ignoredModels: [__dirname + '/models/**/*.js'], // OPTIONAL: paths/globs to ignore files
sequelize: sequelize, // sequelize instance
sync: true, // sync models - default false
// forceSync: false // force sync (drops tables) - default false
}
]
}
])
console.log(HapiSequelize.instances.getModel('db','Contact')) // return error
it's return Error: hapi-sequelizejs cannot find the Contact model
here is my directory structure:
and this is my contact model:
@arbisyarifudin in which file did you instantiated the sequelize? Also could you try to export the model using module.exports
?
I am using postgres with sequelize. Here is what my code looks like:
When I log
req.server.plugins['hapi-sequelizejs'][Config.db.name].getModels()
I get an empty object. Here is what my model definition looks like:Not sure what the problem is here.
P.S. I have confirmed that the location of the models glob is correct by manually using
node-glob
.