Updated method with join

This commit is contained in:
2026-05-24 12:16:36 +02:00
parent 134f77c5a3
commit d389b93cc5

View File

@@ -39,18 +39,25 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
/// Retrieves all players belonging to a specific group by [groupId]. /// Retrieves all players belonging to a specific group by [groupId].
Future<List<Player>> getPlayersOfGroup({required String groupId}) async { Future<List<Player>> getPlayersOfGroup({required String groupId}) async {
final query = select(playerGroupTable) final query = select(playerGroupTable).join([
..where((pG) => pG.groupId.equals(groupId)); innerJoin(
final result = await query.get(); playerTable,
playerTable.id.equalsExp(playerGroupTable.playerId),
),
])..where(playerGroupTable.groupId.equals(groupId));
List<Player> groupMembers = List.empty(growable: true); final results = await query.map((row) => row.readTable(playerTable)).get();
return results
for (var entry in result) { .map(
final player = await db.playerDao.getPlayerById(playerId: entry.playerId); (result) => Player(
groupMembers.add(player); id: result.id,
} createdAt: result.createdAt,
name: result.name,
return groupMembers; nameCount: result.nameCount,
description: result.description,
),
)
.toList();
} }
/// Checks if a player with [playerId] is in the group with [groupId]. /// Checks if a player with [playerId] is in the group with [groupId].