itslekan
itslekan5d ago

Database Structure Help

Hey I need a little help trying to structure my database. I'm making a tenant management app. There are multiple managers and each manager can create multiple properties and add one tenant per property. There is a page that allows the manager to view all his tenants but for that to work I need to get all their properties and then get all the tenants under each property It feels really tedieous and I was wondering if there is a smarter more proper way to do this I feel like the tenant should also have a manager_id field but I don't know if that's how it should be done The tree normally looks like manager -> property -> tenant but now it's make it manager-> property -> tenant but also manager -> tenant
8 Replies
Convex Bot
Convex Bot5d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart5d ago
Can a property have more than one manager
itslekan
itslekanOP5d ago
No just one atleast for now
erquhart
erquhart5d ago
You've got it right, I wouldn't change anything here. Is the tedium the nested looping to get tenants for a manager?
itslekan
itslekanOP5d ago
Mmhm It's when I have to write authorization. The manager can edit some tenant details so I firstly have to get the property of the tenant and see if it's manager id matches the manager's id Do you also happen to have any good resources for structuring databases. I'm kinda winging it
erquhart
erquhart5d ago
Yeah there's no silver bullet there for the authz part. I have a budget app and ended up putting budgetId on literally every table to make authz straightforward. But my app just so happens to support that data model. For structuring resources I would check the articles on Stack: https://stack.convex.dev/
itslekan
itslekanOP5d ago
Mmhm I see. That's a little reassuring I guess. Thank you so much
erquhart
erquhart5d ago
Here's a relevant article that's referenced a lot: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.