Orderby in including relations

Hi,
Im getting stuck tryin to add a orderBy on my query:

const sponsorships = await this.drizzleClient.query.sponsorshipDbSchema.findMany({
      orderBy: orderByDate,
      where: (sponsorship, { and, eq: whereEq }) => {
        if (!state) {
          return whereEq(sponsorship.type, SponsorshipTypeEnum.REFERRAL_SPONSORSHIP)
        }
        return and(whereEq(sponsorship.state, state), whereEq(sponsorship.type, SponsorshipTypeEnum.REFERRAL_SPONSORSHIP))
      },
      with: {
        mission: {
          columns: { createdAt: true, job: true },
          orderBy: (missions, { asc: orderByAsc }) => [orderByAsc(missions.createdAt)],
          with: { contact: { columns: { firstname: true, lastname: true } }, customer: { columns: { name: true } } },
        },
        sponsee: {
          columns: { createdAt: true, email: true, firstname: true, lastname: true, linkedIn: true, phoneNumber: true },
        },
        user: {
          columns: { createdAt: true, email: true, firstname: true, lastname: true, phoneNumber: true, userId: true },
          with: { company: { columns: { siret: true } } },
        },
      },
    })


I got a typescript error, and even typing it as any, it does not work. (as seen on the screenshot)

Did not find a way to make it work! Any help is appreciable,

Thanks
Screenshot_2024-02-23_at_16.15.48.png
Was this page helpful?