Repository navigation
Description
Issue Description
What are you doing?
I'm using SQLite3 with multiple :memory: databases (part of my unittests, each test starts with a clean database). I try to save a belongsToMany association but it only updates the database for the first connection.
Here is the link to the SSCCE for this issue: https://github.com/erikman/sequelize-sscce/blob/patch-1/src/sscce.js
Log for the SQLite3 test: https://travis-ci.com/papb/sequelize-sscce/jobs/264370701
What do you expect to happen?
In the SSCCE I run the same setup code twice but with different memory databases. I expect both runs to produce the same SQL statements (INSERT INTO userInGroups .... is missing in the second run), so the second run should create a association between my user and group and print:
"userGroups" [
"userGroup"
]
Additional context
This only happens when I use classes for defining the model. If I change to sequelize.define the problem goes away.
Environment
- Sequelize version:5.21.2
- Node.js version: 10.15.2
- Operating System: Ubuntu Linux
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s): sqlite3 with memory backend
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Activity
erikman commentedon Dec 8, 2019
I noticed that moving the class definitions into the test function also fixes the issue, so it may be entirely because I call
initon the classes twice but with differentsequelizeconnections. Maybe it's enough to just document this (or throw an exception if initializing multiple times)?papb commentedon Jan 16, 2020
Thanks for the report and for investigating the problem.
Throwing an error on multiple inits is likely a great idea :) Would you be interested and have time to do a PR?
papb commentedon Jan 16, 2020
I will not tag this as SQLite because my idea is for an error to be thrown if
initis called more than once, regardless of the dialectgithub-actions commentedon Nov 5, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
evanrittenhouse commentedon Feb 5, 2022
@papb would love to take this on if it's still an issue.
WikiRik commentedon Feb 5, 2022
@evanrittenhouse not sure if it's still an issue but feel free to research this and if it's an issue feel free to submit a PR to fix this. Thanks in advance for helping with the development of sequelize!