one to one query

I have a 2 models relation one to one,
visit
and
visit_log
,
visit_log
stores the visitId for reference to the visit table

const result = await this.db.query.visit.findMany({
      where: and(eq(visit.userId, userId)),
      with: {
        visitLog: {}, // Want to filter by a property ???
      },
});


This is the result that I want, however I want to use a where inside visitLog to filter by status

in other hands this is working but typescript is throwing error

const result2 = await this.db
      .select({
        visit: {
          ...visit,
          // @ts-ignore Working but errors
          visitLog,
        },
      })
      .from(visit)
      .innerJoin(visitLog, eq(visit.visitId, visitLog.visitId))
      .where(and(eq(visitLog.status, "pending"), eq(visit.userId, userId)));

The result I want

[{
    visit: {
      visitId: '6d15badd-19a1-4de7-977e-ad13e387173d',
      visitLog: [Object]
    }
  }],

both are working but the first one i'm not able to filter on visitLog object.
in the second aswell are working but there are typescript errors .
Was this page helpful?