import Sequelize from 'sequelize';
import sequelizeConfig from '../sequelize_config';
import { ENV } from '../../../../config/env';
import tokenModel from './tokens';
import topicModel from './topics';
import userModel from './users';

const config = sequelizeConfig[ENV];

const db = {};
const dbUrl = process.env[config.use_env_variable];

const sequelize = dbUrl ? new Sequelize(dbUrl) : new Sequelize(config.database, config.username, config.password, config);

db.Token = sequelize.import('Token', tokenModel);
db.Topic = sequelize.import('Topic', topicModel);
db.User = sequelize.import('User', userModel);

Object.keys(db).forEach(model => model.associate && model.associate(db));

export { db as Models, sequelize };


@@ -635,17 +635,50 @@
 ach(
-model =%3E 
+(key) =%3E %7B%0A  const model = db%5Bkey%5D;%0A  if (
 mode
@@ -692,11 +692,15 @@
 iate
- &&
+) %7B%0A   
  mod
@@ -715,16 +715,23 @@
 iate(db)
+;%0A  %7D%0A%7D
 );%0A%0Aexpo

Fix Model.associate not being called for sequelize (#826)