generateInsertRelationshipSQLs method
Implementation
FutureOr<List<SQL>> generateInsertRelationshipSQLs(
Transaction transaction,
String entityName,
String table,
String field,
dynamic id,
String otherTableName,
List otherIds) {
var retTableScheme = getTableScheme(table);
return retTableScheme.resolveMapped((tableScheme) {
if (tableScheme == null) {
var errorMsg = "Can't find `TableScheme` for table: $table";
_log.severe(errorMsg);
throw StateError(errorMsg);
}
var relationship = tableScheme.getTableRelationshipReference(
sourceTable: table, sourceField: field, targetTable: otherTableName);
if (relationship == null) {
throw StateError(
"Can't find TableRelationshipReference for tables: $table -> $otherTableName\n$tableScheme");
}
var sqls = otherIds.isEmpty
? [SQL.dummy]
: otherIds
.map((otherId) =>
_generateInsertRelationshipSQL(relationship, id, otherId))
.toList();
var constrainSQL = _generateConstrainRelationshipSQL(
tableScheme, table, field, id, otherTableName, otherIds);
var lastIdx = sqls.lastIndex;
var sqlsLast = sqls[lastIdx].ensureNotSharedDummy();
sqls[lastIdx] = sqlsLast;
sqlsLast.posSQL = [constrainSQL];
return sqls;
});
}