Skip to content

belongsToMany not saved for multiple SQLite :memory: connections #11734

Closed

Description

@erikman

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

  1. erikman commented on Dec 8, 2019

    @erikman
    Author

    I noticed that moving the class definitions into the test function also fixes the issue, so it may be entirely because I call init on the classes twice but with different sequelize connections. Maybe it's enough to just document this (or throw an exception if initializing multiple times)?

  2. papb commented on Jan 16, 2020

    @papb
    Member

    Thanks for the report and for investigating the problem.

    Maybe it's enough to just document this (or throw an exception if initializing multiple times)?

    Throwing an error on multiple inits is likely a great idea :) Would you be interested and have time to do a PR?

  3. added
    existing workaround
    good first issue
    status: understood
    type: bug
    on Jan 16, 2020
  4. papb commented on Jan 16, 2020

    @papb
    Member

    I will not tag this as SQLite because my idea is for an error to be thrown if init is called more than once, regardless of the dialect

  5. assigned and unassigned on Jan 16, 2020
  6. added
    Great SSCCE
    on Jan 24, 2020
  7. github-actions commented on Nov 5, 2021

    @github-actions
    Contributor

    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. 🙂

  8. evanrittenhouse commented on Feb 5, 2022

    @evanrittenhouse
    Contributor

    @papb would love to take this on if it's still an issue.

  9. WikiRik commented on Feb 5, 2022

    @WikiRik
    Member

    @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!

  10. self-assigned this
    on Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Great SSCCEexisting workaroundgood first issuestatus: understoodtype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions