4

I want to make in Sequelize a ternary relationship as seen in the picture below

Image https://www.dropbox.com/s/v8bgsir2qqw6ccv/relationship%20.jpg

If I apply this code in sequelize

A.hasMany(B);
A.hasMany(C);
B.hasMany(C);
C.hasMany(A);
C.hasMany(B);

The resulting SQL code is as follows

CREATE TABLE IF NOT EXISTS `a_b_` (
  PRIMARY KEY (`BId`,`AId`)
) 
CREATE TABLE IF NOT EXISTS `a_c_` (
  `CId` int(11) NOT NULL DEFAULT '0',
  `AId` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`CId`,`AId`)
) 
CREATE TABLE IF NOT EXISTS `b_c_` (
  PRIMARY KEY (`CId`,`BId`)
)

But the result should be

 CREATE TABLE IF NOT EXISTS `a_b_` (
  PRIMARY KEY (`BId`,`AId`)
) 
CREATE TABLE IF NOT EXISTS `a_b_c_` (
  `AId` int(11) NOT NULL DEFAULT '0',
  `BId` int(11) NOT NULL DEFAULT '0', 
  `CId` int(11) NOT NULL DEFAULT '0',

  PRIMARY KEY (`AId`,`BId`, 'CId')
) 

I just can not get create a table with pk (AId, BId, CId) someone could indicate me which way to go or what I can do.

Thanks so much.

CMM
  • 311
  • 3
  • 9

0 Answers0