Browse Source

Fixing a variety of issues with internal relationships and external SQL relationships.

pull/4023/head
mike12345567 5 years ago
parent
commit
7624390f0b
  1. 3
      packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte
  2. 17
      packages/server/src/api/controllers/row/ExternalRequest.ts
  3. 2
      packages/server/src/db/linkedRows/LinkController.js
  4. 2
      packages/server/src/integrations/base/sql.ts
  5. 2
      packages/server/src/integrations/mysql.ts
  6. 9
      packages/server/src/integrations/utils.ts

3
packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte

@ -199,6 +199,9 @@
delete datasource.entities[toTable.name].schema[originalToName]
}
// store the original names so it won't cause an error
originalToName = toRelationship.name
originalFromName = fromRelationship.name
await save()
await tables.fetch()
}

17
packages/server/src/api/controllers/row/ExternalRequest.ts

@ -25,10 +25,10 @@ interface ManyRelationship {
interface RunConfig {
id: string
row: Row
filters: SearchFilters
sort: SortJson
paginate: PaginationJson
row: Row
}
module External {
@ -89,8 +89,9 @@ module External {
// build id array
let idParts = []
for (let field of primary) {
if (row[field]) {
idParts.push(row[field])
const fieldValue = row[`${table.name}.${field}`]
if (fieldValue) {
idParts.push(fieldValue)
}
}
if (idParts.length === 0) {
@ -115,7 +116,11 @@ module External {
const thisRow: { [key: string]: any } = {}
// filter the row down to what is actually the row (not joined)
for (let fieldName of Object.keys(table.schema)) {
thisRow[fieldName] = row[fieldName]
const value = row[`${table.name}.${fieldName}`]
// all responses include "select col as table.col" so that overlaps are handled
if (value) {
thisRow[fieldName] = value
}
}
thisRow._id = generateIdForRow(row, table)
thisRow.tableId = table._id
@ -191,7 +196,7 @@ module External {
const isUpdate = !field.through
const thisKey: string = isUpdate ? "id" : linkTablePrimary
// @ts-ignore
const otherKey: string = isUpdate ? field.foreignKey : tablePrimary
const otherKey: string = isUpdate ? field.fieldName : tablePrimary
row[key].map((relationship: any) => {
// we don't really support composite keys for relationships, this is why [0] is used
manyRelationships.push({
@ -442,7 +447,7 @@ module External {
.filter(
column =>
column[1].type !== FieldTypes.LINK &&
!existing.find((field: string) => field.includes(column[0]))
!existing.find((field: string) => field === column[0])
)
.map(column => `${table.name}.${column[0]}`)
}

2
packages/server/src/db/linkedRows/LinkController.js

@ -322,7 +322,7 @@ class LinkController {
// remove schema from other table
let linkedTable = await this._db.get(field.tableId)
delete linkedTable.schema[field.fieldName]
this._db.put(linkedTable)
await this._db.put(linkedTable)
}
/**

2
packages/server/src/integrations/base/sql.ts

@ -151,7 +151,7 @@ function buildRead(knex: Knex, json: QueryJson, limit: number): KnexQuery {
}
// handle select
if (resource.fields && resource.fields.length > 0) {
query = query.select(resource.fields)
query = query.select(resource.fields.map(field => `${field} as ${field}`))
} else {
query = query.select("*")
}

2
packages/server/src/integrations/mysql.ts

@ -242,7 +242,7 @@ module MySQLModule {
const input = this._query(json, { disableReturning: true })
let row
// need to manage returning, a feature mySQL can't do
if (operation === "awdawd") {
if (operation === operation.DELETE) {
row = this.getReturningRow(json)
}
const results = await internalQuery(this.client, input, false)

9
packages/server/src/integrations/utils.ts

@ -40,8 +40,13 @@ export function breakRowIdField(_id: string): any[] {
// have to replace on the way back as we swapped out the double quotes
// when encoding, but JSON can't handle the single quotes
const decoded: string = decodeURIComponent(_id).replace(/'/g, '"')
const parsed = JSON.parse(decoded)
return Array.isArray(parsed) ? parsed : [parsed]
try {
const parsed = JSON.parse(decoded)
return Array.isArray(parsed) ? parsed : [parsed]
} catch (err) {
// wasn't json - likely was handlebars for a many to many
return [_id]
}
}
export function convertType(type: string, map: { [key: string]: any }) {

Loading…
Cancel
Save