-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem when adding models #465
Comments
Hey @eBuccaneer, can you provide an example repo, which reproduces the issue? From what I can see , your model setup looks good. |
Hey, thanks for the quick reply @RobinBuschmann! I have figured out my problem by now, it was that I have a shared module with own dependencies and node_modules that includes the sequelize model classes, and a server module, where I create the sequelize instance, add models (from the shared module), and sync the database. If you still need the repo to reproduce the error, just drop a message. |
No, thanks, thats not necessary anymore. Good to here that you figured it out! |
I ended up with the same problem: I'm building a shared module that initializes the Sequelize connection, whereas models are defined per-application in their respective app modules (that consume the shared module as a dependency). As soon as I try adding associations between models (even though all models are defined in the same app module), I end up with the same error:
From what the
This is what I had to do in order for associations in models to work: - import { Model } from 'sequelize-typescript'
+ import { Model } from 'sharedModule/node_modules/sequelize-typescript' @eBuccaneer is it how you solved it in your case ? It seems hackish, since some package managers might use a different layout for node_modules, but for app-level modules (which aren't usually depended upon and where the primary user controls the PM used), it seems to work. |
@franky47 I ended up installing the sequelize-typescript dependency only once in the project root and not in the specific module directories, so every module that depends on it uses the same. |
Hi guys, I am facing the same error here! When I use the sync method, it creates all the database with all the dependencies, normally and correct. But now I am using the cli-typescript to run migrations and seeders, which works, but when I try to instantiate the Sequelize get the same error. Already tried the @canary, the @next version from sequelize-typescript, and nothing works, can you see what I am missing? The error:
My package.json:
How it is being instantiate
The code:Access.ts
Action.ts: Has references to another models
Resource.ts: Has references to another models
Tks |
Hey @rvalim, can you provide an example repo which reproduces the issue please? |
Hi @RobinBuschmann I copied the original branch to here Using the project gama-auth, follow the instructions:
on the folder ./services/gama-auth run the bash bellow
Sorry but it is a little bit verbose. Thank you so much |
Hey @rvalim I didn't get any errors. Can you provide a simpler example? |
When I run my application returns the mentioned error. Just tried to use the sequelize-cli instead of sequelize-cli-typescript, everything worked just fine. Bellow my package.json config, do you see any problem of doing like this? When I run sequelize model:generation it creates the js version, but I can create the models by myself.
Tks |
Since sequelize-cli-typescript doesn't seem to be maintained anymore, its definitely better to use sequelize-cli instead. In general I cannot recommend the one or the other, because I never used these tools. Sry |
thank you @RobinBuschmann |
Hi,
i have two models:
and:
But when I start the app, it fails at
sequelize.addModels([/** models */])
with:So I tracked it down to this inside of
mixins.js
hasMany() function:which is unfortunately false somehow.
Removing it inside of
hasMany()
andsingleLinked()
inmixins.js
lets the application start normally without errors and the database tables are created correctly too, but thats pretty dirty and i assume future errors will pop up.I would appreciate any help on how to solve this, thank you!
Update:
Used versions:
The text was updated successfully, but these errors were encountered: