Skip to content
Discussion options

You must be logged in to vote

Yes, I think the documentation around the $dynamic() queries is not perfectly clear that you still cannot call a method more than once.
In your case, the where method used in the function withEnabled is overriding the where used in getSize.
To solve your problem, you don't really need to use the withEnabled function, you just need to add the filter conditionally like this:

async function getSize(id: string, options: Pick<Options, "enabled"> = {
  enabled: DEFAULT_OPTIONS.enabled,
}): Promise<InferSelectModel<typeof sizeSchema>> {
  const { enabled = DEFAULT_OPTIONS.enabled } = options;
  let query = db.select().from(sizeSchema).where(and(
      eq(sizeSchema.id, id),
      enabled !== und…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by riculum
Comment options

You must be logged in to vote
2 replies
@riculum
Comment options

@Angelelz
Comment options

Angelelz Jan 7, 2024
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants