hyperzone
hyperzone•13mo ago

'remove' in convex-ents patch not working

I'm reposting this from my old thread that didn't get any replies: Creating many to many ents works (using add inside a patch), but remove doesn't work on both sides:
const category = await ctx
.table("categories")
.getX(categoryId); // Id<"categories">

await category.patch({
items: {
remove: items, // Id<"items">[]
},
});
const category = await ctx
.table("categories")
.getX(categoryId); // Id<"categories">

await category.patch({
items: {
remove: items, // Id<"items">[]
},
});
the other side also doesn't work which is - getX each item and remove [category_.id] in a patch call this is the relevant part of the schema:
categories: defineEnt({
name: v.any(),
description: v.any(),
})
.field("isEnabled", v.boolean(), { default: true })
.edge("menu")
.edges("items"),
items: defineEnt({
name: v.any(),
description: v.any(),
price: v.float64(),
isEnabled: v.boolean(),
})
// item can be in multiple menus and categories
.edges("categories")
.edges("menus")
.edge("businesse"),
categories: defineEnt({
name: v.any(),
description: v.any(),
})
.field("isEnabled", v.boolean(), { default: true })
.edge("menu")
.edges("items"),
items: defineEnt({
name: v.any(),
description: v.any(),
price: v.float64(),
isEnabled: v.boolean(),
})
// item can be in multiple menus and categories
.edges("categories")
.edges("menus")
.edge("businesse"),
I'm not getting errors or anything, it just executes the mutation but the relevant categories_to_items document doesn't get deleted
5 Replies
Michal Srb
Michal Srb•13mo ago
Hey @hyperzone I meant to get to this but it slipped. Sounds like a bug! I can reproduce the issue. @hyperzone I published convex-ents version 0.4.3 with the fix, please upgrade and try again.
hyperzone
hyperzoneOP•13mo ago
Thank you it is now working 🙂 @Michal Srb Also a question, right now if I run a mutation that creates a many:many edge between 'menu' and 'item' for example, then run it again with the same menu and item ids, it creates a new menu_to_items document. Shouldn't it be like 'there's already an edge between the item and the menu so don't do anything'?
Michal Srb
Michal Srb•13mo ago
Yes, that also sounds like a bug
hyperzone
hyperzoneOP•13mo ago
Sorry for bumping this, but did it get fixed?
Michal Srb
Michal Srb•13mo ago
@hyperzone sorry I am out this week, will have a look on Sunday/Monday. @hyperzone fixed in convex-ents@0.4.4

Did you find this page helpful?