prevent relationships getting overridden in mySQL connector
This commit is contained in:
parent
4b367f0480
commit
83db9754d5
|
@ -140,7 +140,7 @@ module MySQLModule {
|
|||
this.client = mysql.createConnection(config)
|
||||
}
|
||||
|
||||
async buildSchema(datasourceId: string) {
|
||||
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
||||
const tables: { [key: string]: Table } = {}
|
||||
const database = this.config.database
|
||||
this.client.connect()
|
||||
|
@ -193,6 +193,19 @@ module MySQLModule {
|
|||
schema,
|
||||
}
|
||||
}
|
||||
|
||||
// add the existing relationships from the entities if they exist, to prevent them from being overridden
|
||||
if (entities && entities[tableName]) {
|
||||
const existingTableSchema = entities[tableName].schema
|
||||
for (let key in existingTableSchema) {
|
||||
if (!existingTableSchema.hasOwnProperty(key)) {
|
||||
continue
|
||||
}
|
||||
if (existingTableSchema[key].type === "link") {
|
||||
tables[tableName].schema[key] = existingTableSchema[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.client.end()
|
||||
|
|
Loading…
Reference in New Issue