Home:ALL Converter>Create table with Cyclic Dependency in sequelize,

Create table with Cyclic Dependency in sequelize,

Ask Time:2017-08-17T12:56:39         Author:Dila Gurung

Json Formatter

I have created two tables employee and department. An employee has the following attribute:

1. id
2. Name
3. Department(fk, refer to department id )

Department:

1. id
2. HeadOfDepartment(fk, refer to employee id)

As it is pretty clear from above statement, cyclic dependency exists between this two table.

When I run the statement to create this two table using sequelize, it throws "cyclic dependency error", And as suggested by stack overflow, I introduced an attribute called "constraint" and set it to false. and when I query the structure of above table, there was no constraint which means there was no association. Is there any route, where I can create a table with cyclic dependency without introducing the third table and without using "Alter " statement.

Author:Dila Gurung,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45726853/create-table-with-cyclic-dependency-in-sequelize
yy