fix(query): resolve PostgREST grouping error in SessionList
This commit is contained in:
@@ -44,7 +44,6 @@ export default function SessionList() {
|
||||
.select(`
|
||||
*,
|
||||
session_participants (
|
||||
count,
|
||||
buddies (name)
|
||||
),
|
||||
tastings (count)
|
||||
@@ -53,32 +52,38 @@ export default function SessionList() {
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching sessions:', error);
|
||||
// Fallback: try without tastings join if relationship is missing
|
||||
// Fallback: try without tastings join
|
||||
const { data: fallbackData, error: fallbackError } = await supabase
|
||||
.from('tasting_sessions')
|
||||
.select(`
|
||||
*,
|
||||
session_participants (count)
|
||||
session_participants (buddies(name))
|
||||
`)
|
||||
.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,
|
||||
participants: (s.session_participants as any[])?.filter(p => p.buddies).map(p => p.buddies.name) || [],
|
||||
whisky_count: 0
|
||||
})) || []);
|
||||
setSessions(fallbackData.map(s => {
|
||||
const participants = (s.session_participants as any[])?.filter(p => p.buddies).map(p => p.buddies.name) || [];
|
||||
return {
|
||||
...s,
|
||||
participant_count: participants.length,
|
||||
participants: participants,
|
||||
whisky_count: 0
|
||||
};
|
||||
}) || []);
|
||||
}
|
||||
} else {
|
||||
setSessions(data.map(s => ({
|
||||
...s,
|
||||
participant_count: s.session_participants[0]?.count || 0,
|
||||
participants: (s.session_participants as any[])?.filter(p => p.buddies).map(p => p.buddies.name) || [],
|
||||
whisky_count: s.tastings[0]?.count || 0
|
||||
})) || []);
|
||||
setSessions(data.map(s => {
|
||||
const participants = (s.session_participants as any[])?.filter(p => p.buddies).map(p => p.buddies.name) || [];
|
||||
return {
|
||||
...s,
|
||||
participant_count: participants.length,
|
||||
participants: participants,
|
||||
whisky_count: s.tastings[0]?.count || 0
|
||||
};
|
||||
}) || []);
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user