sequelize n:m associations with paranoid throws unique errors
See original GitHub issueMinimal repro
var Sequelize = require("sequelize"),
sequelize = new Sequelize(process.env.DATABASE_URL, {
define: {
paranoid: true,
},
dialect: 'postgres'
}),
Foo = sequelize.define("Foo"),
Bar = sequelize.define("Bar"),
FooBar = sequelize.define("FooBar");
Foo.belongsToMany(Bar, { through: "FooBar" });
Bar.belongsToMany(Foo, { through: "FooBar" });
let myfoo, mybar;
sequelize.sync()
.then(() => Foo.create({}))
.then((foo) => {myfoo=foo; return Bar.create({});})
.then((bar) => {mybar=bar; return myfoo.setBars([mybar]);})
.then(() => myfoo.setBars([]))
.then(() => myfoo.setBars([mybar]))
.then(() => console.log("finish"))
What do you expect to happen?
I did not want the system to violates unique constraint “FooBars_pkey” but it does. Another bug report mentions that paranoid should be disabled for such associations but clearly it’s not. (https://github.com/sequelize/sequelize/issues/809)
Dialect: postgres Database version: “PostgreSQL 9.5.1 on x86_64-apple-darwin15.3.0, compiled by Apple LLVM version 7.0.2 (clang-700.1.81), 64-bit” Sequelize version: 3.24.3
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:17 (6 by maintainers)
Top Results From Across the Web
Paranoid - Sequelize
Sequelize supports the concept of paranoid tables. A paranoid table is one that, when told to delete a record, it will not truly...
Read more >How to return non-unique join table records in sequelize?
The problem resides in that Sequelize, as of v6.3.5, still doesn't directly support duplicate entries from through tables when using BelongToMany associations.
Read more >Sequelize Unique constraint + paranoid - Stack Overflow
What exactly fails when you tried brand name + deleted_at unique constraint? · I rethought about it and changing\redefining the deleteAt field ...
Read more >sequelize/sequelize - Gitter
However when hooks are executed for associations the option is not there ... I found that setting Unique: false and using sequelize db:migrate...
Read more >Model definition - Manual | Sequelize
NOW }, // setting allowNull to false will add NOT NULL to the column, which means an error will be // thrown from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this issue is still a problem - if
paranoid = true
sequelize should setdeletedAt
tonull
on n:m relations that are already setmy workaround is to disable paranoid for relations 😦
I can confirm @oscarr-reyes findings. Assuming we have
users
,userTags
andtags
, andparanoid: true
foruserTags
: