createRelationTable<T> function

T createRelationTable<T>({
  1. required String relationFieldName,
  2. required Column field,
  3. required Column foreignField,
  4. TableRelation? tableRelation,
  5. required T createTable(
    1. TableRelation foreignTableRelation
    ),
})

Creates a new Table containing TableRelation with information about how the tables are joined.

relationFieldName is the reference name of the table join. field is the Column of the table that is used to join the tables. foreignField is the Column of the foreign table that is used to join table. tableRelation is the TableRelation of the table that is used to join the tables.

Implementation

T createRelationTable<T>({
  required String relationFieldName,
  required Column field,
  required Column foreignField,
  TableRelation? tableRelation,
  required T Function(
    TableRelation foreignTableRelation,
  ) createTable,
}) {
  var relationDefinition = TableRelationEntry(
    relationAlias: relationFieldName,
    field: field,
    foreignField: foreignField,
  );

  if (tableRelation == null) {
    return createTable(TableRelation([relationDefinition]));
  }

  return createTable(
    tableRelation.copyAndAppend(relationDefinition),
  );
}