types / sequelize

The typings for https://github.com/sequelize/sequelize
63 stars 37 forks source link

it's necessary to execute a find operation to get models works? #158

Closed dengue8830 closed 6 years ago

dengue8830 commented 6 years ago

i used this example code and in my main app.ts i have this code

import { User } from './components/user/user';
import { Group } from './components/user/group';
import sequelize from './common/connection';
sequelize.sync({ force: true });

but it's not enough to create tables on database, in order to that i have to execute a find operation

sequelize.sync({ force: true })
    .then(x => {
        User.findAll();
    })
    .catch(error => {
        console.error(error);
    });

it's mandatory? must i execute a find operation for all my models? which is the simplest way to sync all my models?

in the sequelize no typescript version it's enough with a simple import of the models

Thanks

felixfbecker commented 6 years ago

I don't fully understand your question? Are you saying the first example doesn't create the tables? You are missing a then/catch handler in the first example

dengue8830 commented 6 years ago

sorry, it was an asynchronous problem, i wasn't waiting sequelize to finish. I thought the work could finish even if i didn't wait for it. My fault