code: function hookupSubModels (models) {
    // hook up sub-models
    for (const namespace of Object.values(models)) {
      for (const [modelId, model] of Object.entries(namespace)) {
        for (const fkConstraint of Object.values(model.fkConstraints || {})) {
          const [parentSchemaName, parentTableName] = fkConstraint.targetTable.split('.')
          const parentNamespaceId = _.camelCase(parentSchemaName)
          const parentPropertyId = _.camelCase(parentTableName)
          const parentModel = models[parentNamespaceId][parentPropertyId]
          const parentColumns = fkConstraint.sourceColumns
          const childColumns = fkConstraint.targetColumns
  
          const columnJoin = {}
          for (const i in parentColumns) {
            columnJoin[parentColumns[i]] = childColumns[i]
          }
  
          parentModel.subModels[modelId] = {
            model: model,
            columnJoin: columnJoin,
            sourceProperties: fkConstraint.sourceColumns.map(_.camelCase),
            targetProperties: fkConstraint.targetColumns.map(_.camelCase)
          }
  
          parentModel.subDocIds.push(modelId)
        }
      }
    }
  }
docs: createModels