© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•8mo ago
Shimple

How to refine seed data using `with` clause in drizzle seed

I have a table called
workout
workout
that has a one-to-many relationship to another table called
exercise
exercise
(i.e one workout has many exercises associated with it). Now, when I try to seed some workouts, I want to be able to seed each workout
with
with
multiple exercises. I want to be able to refine what parameters are allowed for the nested exercises, but I see no way to do that.
Here's what I have:
await seed(db, { workout, exercise }).refine((funcs) => ({
    workout: {
      count: 3,
      columns: {
        title: funcs.valuesFromArray({ values: workoutTitleList }),
      },
      with: {
        exercise: 3,
      },
    },
  }));
await seed(db, { workout, exercise }).refine((funcs) => ({
    workout: {
      count: 3,
      columns: {
        title: funcs.valuesFromArray({ values: workoutTitleList }),
      },
      with: {
        exercise: 3,
      },
    },
  }));

And here's what I want (but don't see that I can actually accomplish):
await seed(db, { workout, exercise }).refine((funcs) => ({
    workout: {
      count: 3,
      columns: {
        title: funcs.valuesFromArray({ values: workoutTitleList }),
      },
      with: {
          exercise: {
            columns: {
                title: funcs.valuesFromArray({ values: predefinedListOfExerciseTitles })
            }
          }
      },
    },
  }));
await seed(db, { workout, exercise }).refine((funcs) => ({
    workout: {
      count: 3,
      columns: {
        title: funcs.valuesFromArray({ values: workoutTitleList }),
      },
      with: {
          exercise: {
            columns: {
                title: funcs.valuesFromArray({ values: predefinedListOfExerciseTitles })
            }
          }
      },
    },
  }));

As you can see, I want to have a pre-defined set of exercises that are randomly chosen from and tied to each workout. So, what's the solution to making this happen?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to use drizzle-seed to seed data?
Drizzle TeamDTDrizzle Team / help
15mo ago
Seed refine custom data
Drizzle TeamDTDrizzle Team / help
4mo ago
Does Drizzle support using INSERT statements in a WITH clause?
Drizzle TeamDTDrizzle Team / help
2y ago
drizzle-seed
Drizzle TeamDTDrizzle Team / help
13mo ago