-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Unwanted primary key when self referencing through #1891
Copy link
Copy link
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
Tested on master:
var Sequelize = require('sequelize')
var pg = require('pg')
var sequelize = new Sequelize(process.env.DATABASE_URL || 'postgres://postgres:postgres@localhost/sequelize-test')
var User = sequelize.define('User',{})
var Following = sequelize.define('Following',{})
User.hasMany(User,{ through: Following, as: 'Follower', foreignKey: 'FollowerId' })
User.hasMany(User,{ through: Following, as: 'Followed', foreignKey: 'FollowedId' })
sequelize.sync({ force: true }).success(function(){
console.log('done');
});
This executes following SQL code according to Following model:
CREATE TABLE "Followings" (
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL
,"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL
,"FollowedId" INT REFERENCES "Users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
,"FollowerId" INT REFERENCES "Users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
,UNIQUE (
"FollowedId"
,"FollowerId"
)
,PRIMARY KEY ("FollowerId")
)
As you can see there is PRIMARY KEY ("FollowerId") - and it shouldnt be there... How I can force Sequelize not to add this PK?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type