You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a many-to-many relation between users and projects.
I want to be able to allow a user to delete a project if the project is attached to that user.
I can retrieve project data for a given user using the many-to-many reference object (assuming this is the intended way?):
But I am unable to delete a project on condition. With that I mean, if I db.delete(usersOnProjects), then only the row in the relation table is deleted, not the the project.
On the other hand, if I run db.delete(project) I can where() by projectId, but have no way of including a userId condition.
this is my schema:
// userexportconstuser=pgTable('user',{id: text('id').primaryKey()username: citext('username').unique().notNull(),});exportconstuserRelations=relations(user,({ many })=>({usersOnProjects: many(usersOnProjects),}));
// projectexportconstproject=pgTable('project',{id: text('id').primaryKey(),name: citext('name').notNull().unique(),});exportconstprojectRelations=relations(project,({ many })=>({usersOnProjects: many(usersOnProjects)}));
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a many-to-many relation between users and projects.
I want to be able to allow a user to delete a project if the project is attached to that user.
I can retrieve project data for a given user using the many-to-many reference object (assuming this is the intended way?):
But I am unable to delete a project on condition. With that I mean, if I
db.delete(usersOnProjects)
, then only the row in the relation table is deleted, not the the project.On the other hand, if I run
db.delete(project)
I canwhere()
byprojectId
, but have no way of including auserId
condition.this is my schema:
Beta Was this translation helpful? Give feedback.
All reactions