MCPcopy
hub / github.com/sequelize/sequelize / _syncModelsWithCyclicReferences

Method _syncModelsWithCyclicReferences

src/sequelize.js:842–863  ·  view source on GitHub ↗

* Used instead of sync() when two models reference each-other, so their foreign keys cannot be created immediately. * * @param {object} options - sync options * @private

(options)

Source from the content-addressed store, hash-verified

840 * @private
841 */
842 async _syncModelsWithCyclicReferences(options) {
843 if (this.dialect.name === 'sqlite') {
844 // Optimisation: no need to do this in two passes in SQLite because we can temporarily disable foreign keys
845 await withSqliteForeignKeysOff(this, options, async () => {
846 for (const model of this.modelManager.models) {
847 await model.sync(options);
848 }
849 });
850
851 return;
852 }
853
854 // create all tables, but don't create foreign key constraints
855 for (const model of this.modelManager.models) {
856 await model.sync({ ...options, withoutForeignKeyConstraints: true });
857 }
858
859 // add foreign key constraints
860 for (const model of this.modelManager.models) {
861 await model.sync({ ...options, force: false, alter: true });
862 }
863 }
864
865 /**
866 * Truncate all tables defined through the sequelize models.

Callers 1

syncMethod · 0.95

Calls 2

withSqliteForeignKeysOffFunction · 0.85
syncMethod · 0.45

Tested by

no test coverage detected