What should I define here, if i want to reference another table by ID?
Hello fellow Convexers,
My question is that, because i can't figure it out, what should I put on Line#59, here:
https://github.com/andrejmoltok/oceans5/blob/O5T-6-Userlist-Convex-RW/convex/users.ts#L59
if I have defined the table in my schema as is on Line#52 here:
https://github.com/andrejmoltok/oceans5/blob/O5T-6-Userlist-Convex-RW/convex/schema.ts#L52
Typescript says it cannot be assigned as string nor viceversa. what comes on line 59 in the users.ts file?
Can anyone help please?
GitHub
oceans5/convex/users.ts at O5T-6-Userlist-Convex-RW · andrejmoltok/...
Oceans5 is a BattleShip clone game in Next.js. Contribute to andrejmoltok/oceans5 development by creating an account on GitHub.
GitHub
oceans5/convex/schema.ts at O5T-6-Userlist-Convex-RW · andrejmoltok...
Oceans5 is a BattleShip clone game in Next.js. Contribute to andrejmoltok/oceans5 development by creating an account on GitHub.
4 Replies
How is an alliance created? If you create an alliance for every user, you can do something like:
However, if an alliance is only created later and users may or may not have one, you might want to define alliance as:
in your schema
If you might have many alliances for the same user, you might instead do something like not having
alliance
on the user document, but instead user
on the alliances document:
where this is a "one to many" relationship, which you can read more about here: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas#one-to-manyRelationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
specifically for the alliances -> user strategy: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas#back-references-scalable
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
Hey @ian i'm going with setting it with
v.optional()
, because in my game project the user may or may not be part of an alliance. Thank you for the docs as well.