withOrganisationUnit method

UserQuery withOrganisationUnit()

Implementation

UserQuery withOrganisationUnit() {
  final userOrganisationUnit =
      Repository<UserOrganisationUnit>(database: database as Database);
  final Column? relationColumn = userOrganisationUnit.columns.firstWhere(
      (column) =>
          column.relation?.referencedEntity?.tableName == this.tableName);

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

  return this;
}