orenmizr
DTDrizzle Team
•Created by orenmizr on 9/4/2023 in #help
Help creating many to many (user has many followers, user has many followees)
what i have understood since then:
- since i had 2 many on the same table, it requested that i use relation name (i think so it can match between them)
- i thought the studio is like prisma when you have connected entities if you click user's follower relation - you should see the users.... so i thought the fact that i am seeing the connecting table means i did not correctly defined my relation...
15 replies
DTDrizzle Team
•Created by orenmizr on 9/4/2023 in #help
Help creating many to many (user has many followers, user has many followees)
i have to continue reading to further understand... i wish someone will publish a drizzle repo will all the possible relations and the gotchas... thanks. it helped a lot.
15 replies
DTDrizzle Team
•Created by orenmizr on 9/4/2023 in #help
Help creating many to many (user has many followers, user has many followees)
it did fix the issue... i love this drizzle thing... it forces me to dust off my sql skills... i got this response:
followers: [ { followerId: 1, followeeId: 2, follower: [Object] } ],
followees: [
{ followerId: 2, followeeId: 1, followee: [Object] },
{ followerId: 3, followeeId: 1, followee: [Object] },
{ followerId: 4, followeeId: 1, followee: [Object] }
]
}
for user id = 1
sql wise i feel correct... but i thought with the relation and studio - when i click on a follower it will show my the user entity that follows... i don't really care about the connecting table... it is just something i have to do for manytomany
15 replies
DTDrizzle Team
•Created by orenmizr on 9/4/2023 in #help
Help creating many to many (user has many followers, user has many followees)
turns out my drizzle crashed:
nitro] [unhandledRejection] Error: Relation followers not found tried to push migrate and got crashed too - error: column "follower_id" is in a primary key... spent 2 hours on this yesterday...
nitro] [unhandledRejection] Error: Relation followers not found tried to push migrate and got crashed too - error: column "follower_id" is in a primary key... spent 2 hours on this yesterday...
15 replies
DTDrizzle Team
•Created by orenmizr on 9/4/2023 in #help
Help creating many to many (user has many followers, user has many followees)
15 replies
DTDrizzle Team
•Created by orenmizr on 9/4/2023 in #help
Help creating many to many (user has many followers, user has many followees)
nice catch @tomeverson ! i added the code below, studio stops throwing errors... i gave them the same realtionNames from above - is that the idea ? or am i mistaken. not sure how it works in drizzle
export const userFollowRelations = relations(usersFollowers, ({ one }) => ({
follower: one(users, {
fields: [usersFollowers.followerId],
references: [users.id],
relationName: "followers",
}),
followee: one(users, {
fields: [usersFollowers.followeeId],
references: [users.id],
relationName: "followees",
}),
}));
15 replies