fix: add defensive fallbacks for missing database relationships

This commit is contained in:
2025-12-18 20:35:38 +01:00
parent 68ac7a515e
commit c63a348e6b
3 changed files with 44 additions and 1 deletions

View File

@@ -40,6 +40,24 @@ export default function SessionList() {
if (error) {
console.error('Error fetching sessions:', error);
// Fallback: try without tastings join if relationship is missing
const { data: fallbackData, error: fallbackError } = await supabase
.from('tasting_sessions')
.select(`
*,
session_participants (count)
`)
.order('scheduled_at', { ascending: false });
if (fallbackError) {
console.error('Error fetching sessions fallback:', fallbackError);
} else {
setSessions(fallbackData.map(s => ({
...s,
participant_count: s.session_participants[0]?.count || 0,
whisky_count: 0
})) || []);
}
} else {
setSessions(data.map(s => ({
...s,