Skip to content
Init is coming / May 19 - 23
Back

One-to-many relationship - way to quickly seed

  • 0
  • Databases
  • Cloud
Grahf
27 Feb, 2025, 18:07

Title probably makes no sense - sorry. But I'm trying to create a database for buildings with units. Eight buildings each with eight units. So I made a buildings collection that looks like this screenshot.

Then I made a collection called units. It has a attribute called unit_letter which is an enum that can be A,B,C,D,E,F,G, or H. The only other attribute is type "relationship". Not sure if it should be a one-way or two-way relationship. Both seem to work?

In any case is there a way to quickly fill in the units collection? In normal SQL it would be something like this:

TypeScript
INSERT INTO condos (building_id, unit_label) VALUES
(1, 'A'), (1, 'B'), (1, 'C'), (1, 'D'), (1, 'E'), (1, 'F'), (1, 'G'), (1, 'H'),
(2, 'A'), (2, 'B'), (2, 'C'), (2, 'D'), (2, 'E'), (2, 'F'), (2, 'G'), (2, 'H');
...
TL;DR
Developers trying to set up a one-to-many relationship for buildings with units. Created a buildings collection and a units collection with the necessary attributes. Questioning whether the relationship attribute should be one-way or two-way. To quickly fill in the units collection, consider using a script to add units for each building, similar to the SQL example provided.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more