fix: add defensive fallbacks for missing database relationships
This commit is contained in:
@@ -39,7 +39,7 @@ export default async function BottlePage({
|
||||
notFound();
|
||||
}
|
||||
|
||||
const { data: tastings } = await supabase
|
||||
const tastingsResult = await supabase
|
||||
.from('tastings')
|
||||
.select(`
|
||||
*,
|
||||
@@ -57,6 +57,28 @@ export default async function BottlePage({
|
||||
.eq('bottle_id', params.id)
|
||||
.order('created_at', { ascending: false });
|
||||
|
||||
let tastings = tastingsResult.data;
|
||||
|
||||
if (tastingsResult.error) {
|
||||
console.error('Error fetching tastings with sessions:', tastingsResult.error);
|
||||
// Fallback: try without session join if relationship is missing
|
||||
const fallbackResult = await supabase
|
||||
.from('tastings')
|
||||
.select(`
|
||||
*,
|
||||
tasting_tags (
|
||||
buddies (
|
||||
id,
|
||||
name
|
||||
)
|
||||
)
|
||||
`)
|
||||
.eq('bottle_id', params.id)
|
||||
.order('created_at', { ascending: false });
|
||||
|
||||
tastings = fallbackResult.data;
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-zinc-50 dark:bg-black p-4 md:p-12 lg:p-24">
|
||||
<div className="max-w-4xl mx-auto space-y-6 md:space-y-12">
|
||||
|
||||
Reference in New Issue
Block a user