withSections method

DataSetQuery withSections()

Implementation

DataSetQuery withSections() {
  final dataSetSection =
      Repository<DataSetSection>(database: database as Database);

  final Column? relationColumn = dataSetSection.columns.firstWhere((column) =>
      column.relation?.referencedEntity?.tableName == this.tableName);

  if (relationColumn != null) {
    ColumnRelation relation = ColumnRelation(
        referencedColumn: relationColumn.relation?.attributeName,
        attributeName: 'sections',
        primaryKey: this.primaryKey?.name,
        relationType: RelationType.OneToMany,
        referencedEntity: Entity.getEntityDefinition(
            AnnotationReflectable.reflectType(DataSetSection) as ClassMirror),
        referencedEntityColumns: Entity.getEntityColumns(
            AnnotationReflectable.reflectType(DataSetSection) as ClassMirror,
            false));

    this.relations.add(relation);
  }

  return this;
}