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