Update many to many

This commit is contained in:
adrinr 2023-02-22 10:54:55 +00:00
parent 3539656fcc
commit d9bc01782d
3 changed files with 8 additions and 11 deletions

View File

@ -629,10 +629,7 @@ export class ExternalRequest {
* Creating the specific list of fields that we desire, and excluding the ones that are no use to us * Creating the specific list of fields that we desire, and excluding the ones that are no use to us
* is more performant and has the added benefit of protecting against this scenario. * is more performant and has the added benefit of protecting against this scenario.
*/ */
buildFields( buildFields(table: Table, includeRelations: boolean) {
table: Table,
includeRelations: IncludeRelationship = IncludeRelationship.INCLUDE
) {
function extractRealFields(table: Table, existing: string[] = []) { function extractRealFields(table: Table, existing: string[] = []) {
return Object.entries(table.schema) return Object.entries(table.schema)
.filter( .filter(
@ -691,6 +688,10 @@ export class ExternalRequest {
} }
filters = buildFilters(id, filters || {}, table) filters = buildFilters(id, filters || {}, table)
const relationships = this.buildRelationships(table) const relationships = this.buildRelationships(table)
const includeSqlRelationships =
config.includeSqlRelationships === IncludeRelationship.INCLUDE
// clean up row on ingress using schema // clean up row on ingress using schema
const processed = this.inputProcessing(row, table) const processed = this.inputProcessing(row, table)
row = processed.row row = processed.row
@ -708,9 +709,7 @@ export class ExternalRequest {
}, },
resource: { resource: {
// have to specify the fields to avoid column overlap (for SQL) // have to specify the fields to avoid column overlap (for SQL)
fields: isSql fields: isSql ? this.buildFields(table, includeSqlRelationships) : [],
? this.buildFields(table, config.includeSqlRelationships)
: [],
}, },
filters, filters,
sort, sort,

View File

@ -58,7 +58,7 @@ export async function patch(ctx: BBContext) {
return handleRequest(Operation.UPDATE, tableId, { return handleRequest(Operation.UPDATE, tableId, {
id: breakRowIdField(id), id: breakRowIdField(id),
row: inputs, row: inputs,
includeSqlRelationships: IncludeRelationship.EXCLUDE, includeSqlRelationships: IncludeRelationship.INCLUDE,
}) })
} }

View File

@ -502,9 +502,7 @@ class InternalBuilder {
if (opts.disableReturning) { if (opts.disableReturning) {
return query.update(parsedBody) return query.update(parsedBody)
} else { } else {
return query return query.update(parsedBody).returning("*")
.update(parsedBody)
.returning(generateSelectStatement(json, knex))
} }
} }