I notice you do a lot of dev migrations (around 26:00). I'd recommend using prisma db push to apply changes to the database while in dev and only creating a migration once satisfied everything works as intended. This keeps the migrations history leaner, as it only has major schema changes, no minor ones. Think of it in git terms, you make a lot of commits as you work, then you push or merge once those changes are finalized. Note: I know this is done for demonstration purposes, it's just a tip for viewers.
The many-to-many relation at 13:01 between product and Category doesn't make sense. The one that is defined is one-to-many, not many-to-many I am assuming you will change that later on in the video.
waooo I really liked your video, will you have any video using prism where you compare tables or products ... example I have several stores that sell the same products that can compare the prices of those products and organize them in order from cheapest to most expensive ... examples in that style ...?? or you could guide me how to do it ... greetings Jose Grillo of Venezuela
Thank you very much for your effort, Does Prisma has model inheritance like BaseEntity implementation, if it has, how can we make it with Postgres, if not, is there any promise in the future to make it in Prisma?
@19.29, you're mapping your product category to a random category that was already made in the first transaction. If you were seeding a database with an array of users with an array of tasks, do you know how you'd map a the first element of the items array to the first user in the user array? ie. userid: task[task.map((i, index) => index)].id.....I'm getting Type 'number[]' cannot be used as an index type.ts(2538).
@@TomDoesTech I re-did some of my stuff exactly how you used the index at 24:16 and my errors went away. Unfortunately I'm getting a weird type error now. Have you seen anything like: (property) taskId: { connect: { id: string | undefined; }; } Type '{ connect: { id: string | undefined; }; }' is not assignable to type 'string'.ts(2322) My schema is: model List { id String @id @default(cuid()) name String @unique tasks ListTask[] materials Materials[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model ListTask { id String @id @default(cuid()) taskName String taskDescription String list List @relation(fields: [listId], references: [id]) listId String } My query is: const list = await createList(); //^^ this part creates 10 lists via a transaction in a different file and returns the data const task = await prisma.$transaction( Array(10) .fill(null) .map((_, i) => { return prisma.task.create({ data: { taskName: "Some name" taskDescription: "some description" listId: {
let's suppose we have a user table and multiple profile tables (CustomerProfile, Admin profile) in this case different profiles tables have one relation userID. How are you going to tackle the User table ? do we need to add multiple fields in users table like CustomerProfile? ,AdminProfile
lets how the Polymorphic relationships or BelongTo works on ur case.. (but idk ,it will solve ur case or not with prisma. as i heard in a year ago, prisma doesnt supp it yet ). i cant elaborate them in details, but i believe i had a same case as urs in the prev proj.
Yeah, you could either have a reference on the user for each profile. Or, have a `userProfile` which has all the shared data, then have a reference to each of the distinct tables. To be honest, I'm not 100% why you'd want to do this so there might be a nicer solution.
A bright side of being a night lurker on Brazil: having the opportunity to watch awesome tutorials on Aussie afternoon. Superb tutorial again Tom. 👌🏼
I notice you do a lot of dev migrations (around 26:00). I'd recommend using prisma db push to apply changes to the database while in dev and only creating a migration once satisfied everything works as intended. This keeps the migrations history leaner, as it only has major schema changes, no minor ones. Think of it in git terms, you make a lot of commits as you work, then you push or merge once those changes are finalized.
Note: I know this is done for demonstration purposes, it's just a tip for viewers.
Such an amazing and clear tutorial! 🤩
Thank you so much.... Verymuch needed..... I really mean it... Thank you very much
Thanks for the video! It was just a bit too fast but I'll analyze it with more time
You do incredible work! Love you stuff, especially the more advanced stuff
absolute legend you are
The many-to-many relation at 13:01 between product and Category doesn't make sense.
The one that is defined is one-to-many, not many-to-many
I am assuming you will change that later on in the video.
Awesome, thanks for your efforts
This is very very very useful
@TomDoesTech What is the VSCode extension you are using that is giving your Prisma Syntax Suggestion? That's really cool bro
github copilot
waooo I really liked your video, will you have any video using prism where you compare tables or products ... example I have several stores that sell the same products that can compare the prices of those products and organize them in order from cheapest to most expensive ... examples in that style ...??
or you could guide me how to do it ... greetings Jose Grillo of Venezuela
thank you
Thank you very much for your effort, Does Prisma has model inheritance like BaseEntity implementation, if it has, how can we make it with Postgres, if not, is there any promise in the future to make it in Prisma?
@19.29, you're mapping your product category to a random category that was already made in the first transaction. If you were seeding a database with an array of users with an array of tasks, do you know how you'd map a the first element of the items array to the first user in the user array? ie. userid: task[task.map((i, index) => index)].id.....I'm getting Type 'number[]' cannot be used as an index type.ts(2538).
Map returns an array, so you're trying to get the id prop from an array. You'd need to do task[task.map((i, index) => index)[0]].id
@@TomDoesTech I re-did some of my stuff exactly how you used the index at 24:16 and my errors went away. Unfortunately I'm getting a weird type error now. Have you seen anything like: (property) taskId: { connect: { id: string | undefined; }; } Type '{ connect: { id: string | undefined; }; }' is not assignable to type 'string'.ts(2322)
My schema is:
model List {
id String @id @default(cuid())
name String @unique
tasks ListTask[]
materials Materials[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model ListTask {
id String @id @default(cuid())
taskName String
taskDescription String
list List @relation(fields: [listId], references: [id])
listId String
}
My query is:
const list = await createList();
//^^ this part creates 10 lists via a transaction in a different file and returns the data
const task = await prisma.$transaction(
Array(10)
.fill(null)
.map((_, i) => {
return prisma.task.create({
data: {
taskName: "Some name"
taskDescription: "some description"
listId: {
Fixed my own issue. I just had to query list instead of listId
let's suppose we have a user table and multiple profile tables (CustomerProfile, Admin profile)
in this case different profiles tables have one relation userID.
How are you going to tackle the User table ?
do we need to add multiple fields in users table like CustomerProfile? ,AdminProfile
lets how the Polymorphic relationships or BelongTo works on ur case.. (but idk ,it will solve ur case or not with prisma. as i heard in a year ago, prisma doesnt supp it yet ).
i cant elaborate them in details, but i believe i had a same case as urs in the prev proj.
Yeah, you could either have a reference on the user for each profile. Or, have a `userProfile` which has all the shared data, then have a reference to each of the distinct tables.
To be honest, I'm not 100% why you'd want to do this so there might be a nicer solution.
great tutorial, next time deactivate the autocomplete?
Very poor explanation, designed for trained users who have already worked with Prisma.
Yes. If you haven't used Prisma you're better off starting with a beginners guide or their docs
what are you teaching man? you're not explaining anything. nobody is here to see you coding, we are here to understand stuffs.
Хорош 👍