Is this the right way of using relations ?

hi, this is my first project using drizzle, and I'm not that good at sql query as mostly i use ORMs, but now im using drizzle to learn more sql like syntax,

This is the schema is question:
export const repairOrder = pgTable(
  'repairOrder',
  {
    id: text('id').primaryKey(),
    userId: text('userId').notNull(),
    mechanicId: text('mechanicId'),
    status: roStatusEnum('status').notNull().default('part sent'),
    roNumber: text('roNumber').notNull(),
    carMaker: text('carMaker').notNull(),
    carModel: text('carModel').notNull(),
    createdAt: timestamp('createdAt').notNull().defaultNow(),
    updatedAt: timestamp('updatedAt')
      .defaultNow()
      .$onUpdate(() => new Date())
  } to
  }
)

export const repairOrderFilesRelation = relations(repairOrder, ({  many }) => ({
  files: many(files)
}))

export const files = pgTable(
  'files',
  {
    id: text('id').primaryKey(),
    roId: text('roId').notNull(),
    name: text('name').notNull(),
    key: text('key').notNull(),
    url: text('url').notNull(),
    type: text('type').notNull(),
  }jjk
)

export const fileToRepairOrder = relations(files, ({ one }) => ({
  repairOrder: one(repairOrder, {
    fields: [files.roId],
    references: [repairOrder.id]
  })
}))

and this is the query
      const [data] = await db
        .select()
        .from(repairOrder)
        .innerJoin(estimator, eq(estimator.id, repairOrder.userId))
        .leftJoin(mechanic, eq(mechanic.id, repairOrder.mechanicId))
        .where(eq(repairOrder.id, id))

      const filesData = await db.select().from(files).where(eq(files.roId, id))


I did the relation between files and repair orders, if i try to join them directly into one query (
leftJoin(files, eq(files.roId, repairOrder.id))
) then it will only return 1 file, this is why i splitted it into 2 so i can get all, is this the right way of doing it?
Was this page helpful?