kstulgys
kstulgys10mo ago

how do I create one-to-one edge relation?

tags: defineEnt({
name: v.string(),
}).edge("post"),

posts: defineEnt({
title: v.string(),
body: v.string(),
}).edge("tag"),
tags: defineEnt({
name: v.string(),
}).edge("post"),

posts: defineEnt({
title: v.string(),
body: v.string(),
}).edge("tag"),
One post has one tag and one tag has one post. How do I create these records at the same time? Because one needs to exist before the other.
5 Replies
erquhart
erquhart10mo ago
Reading Ents from the Database - Convex Ents
Relations, default values, unique fields and more for Convex
erquhart
erquhart10mo ago
Oh you're defining, one sec
erquhart
erquhart10mo ago
Ent Schema - Convex Ents
Relations, default values, unique fields and more for Convex
erquhart
erquhart10mo ago
Note that 1:1's have a chicken-and-egg relationship in Convex, you have to create one before you can create the other, hence the { optional: true } in the example linked above.
kstulgys
kstulgysOP10mo ago
oh thanks it works optional is the way

Did you find this page helpful?