Query `with` returning no results?

Hi! Wondering if anyone can see what I'm doing wrong here...

I've got a recipes table that had a relation with recipeTags which, in turn, is related to tags.

I've got a query that's returning the correct recipes, but the recipeTags is empty:

I'm looking at: https://orm.drizzle.team/docs/rqb#find-many
const foundRecipes = await db.query.recipes.findMany({
    ...rest,
    where: eq(recipes.submittedBy, userId),
    columns: {
      id: true,
      ...
    },
    with: { recipeTags: { with: { tags: true } } },
    orderBy: (recipes) => [desc(recipes.createdDate)],
  });


// schema.ts

export const recipes = sqliteTable('recipes', {
  id: text('id').$default(() => createId()).primaryKey(),
  ...
});

export const recipesRelations = relations(recipes, ({ one, many }) => ({
  recipeTags: many(recipeTags),
  ...
}));

export const recipeTags = sqliteTable('recipe_tags', {
  recipeId: text('recipe_id'),
  tagId: text('tag_id'),
  ...
}, (table) => ({
  pk: primaryKey({ columns: [table.recipeId, table.tagId] }),
}));

export const recipeTagsRelations = relations(recipeTags, ({ one }) => ({
  recipes: one(recipes, { fields: [recipeTags.recipeId], references: [recipes.id] }),
  tags: one(tags, { fields: [recipeTags.tagId], references: [tags.id] }),
}));

export const tags = sqliteTable('tags', {
  id: text('id').$default(() => createId()).primaryKey(),
  name: text('name').notNull(),
  isPrivate: integer('is_private', { mode: 'boolean' }).$default(() => false),
  userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),
  createdDate: text('created_date').$default(() => toISO8601(new Date())),
  updatedDate: text('updated_date').$default(() => toISO8601(new Date())),
});

export const tagsRelations = relations(tags, ({ one, many }) => ({
  recipeTags: many(recipeTags),
  menuTags: many(menuTags),
  menuCourseTags: many(menuCourseTags),
  user: one(users, { fields: [tags.userId], references: [users.id] }),
}));
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Was this page helpful?