* Iterate over Models in an order suitable for e.g. creating tables. * Will take foreign key constraints into account so that dependencies are visited before dependents. * * @param {Function} iterator method to execute on each model * @param {object} options * @private * * @depr
(iterator, options)
| 109 | * @deprecated |
| 110 | */ |
| 111 | forEachModel(iterator, options) { |
| 112 | const sortedModels = this.getModelsTopoSortedByForeignKey(); |
| 113 | if (sortedModels == null) { |
| 114 | throw new Error('Cyclic dependency found.'); |
| 115 | } |
| 116 | |
| 117 | options = _.defaults(options || {}, { |
| 118 | reverse: true |
| 119 | }); |
| 120 | |
| 121 | if (options.reverse) { |
| 122 | sortedModels.reverse(); |
| 123 | } |
| 124 | |
| 125 | for (const model of sortedModels) { |
| 126 | iterator(model); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | module.exports = ModelManager; |
nothing calls this directly
no test coverage detected