Cant query with relation using query method

Hi Guys

I facing a challenge where when i query and try to pull out the data from referenced table, it says TypeError: Cannot read properties of undefined (reading 'referencedTable')

here is my schema relations:
export const ratePlanRoomTypeRelation = relations(room_type, ({ many }) => ({
    rate_plans: many(rate_plans),
}))

export const ratePlanRoomTypeRelation2 = relations(rate_plans, ({ one }) => ({
    room_type: one(room_type, {
        fields: [rate_plans.room_type_id],
        references: [room_type.id]
    })
}))

here is my query in sveltekit +page.server.ts
import type { PageServerLoad } from './$types.ts';
import * as schema from '$lib/schema.js';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { PUBLIC_DRIZZLE_DATABASE_URL } from '$env/static/public';
import { eq } from 'drizzle-orm';


const sql = postgres(PUBLIC_DRIZZLE_DATABASE_URL!);
const db = drizzle(sql, { schema: schema });

export const load = (async () => {
    const result = await db.query.room_type.findMany({
        with: {
            rate_plans: true,
            property: true
        },
    });
    
    return {
        data: {
            room_data: result,
        }
    }; // Return a plain object with the result
}) satisfies PageServerLoad;


some facts

  1. if i remove the with property:true, it's working but i can't get the data in property table
  2. i try to double query and join it manually in the code, but not working because the 2nd query that query to the table separately is only able to filter it using single data, which i will have multiple property rows
image.png
Was this page helpful?