Skip to content
Community forum

Coming from Firestore: how do I model subcollections?

SolvedSupero SupportSupero team asked

Common question, written up by the Supero team.

In Firestore we had customers/{id}/orders/{id}. Is there an equivalent, or should each order just store a customer_id string?

Link

1 answer

Accepted answer
Accepted answer

The closest equivalent is a parent relationship. Set parent_type on the child schema to the container schema's bare name (customer), then pass the parent when you create:

python
customer = org.crud.get("customer", customer_uuid)
order = org.crud.create("order", parent=customer, name="order-001", total=199.99)

The SDK fills in fq_name and parent_uuid. Over REST, send parent_uuid and parent_type in the create body. To list one customer's orders, call GET list with ?parent_id=<customer uuid>, or put parent_id in a /list-bulk body when you also need filters.

When the link isn't ownership, such as an order pointing at a coupon, use a reference instead: declare it in the schema's references[], set it with ref-update, and read it with /refs and /back-refs.

Settle this before you import. parent_uuid can't be changed after create, and a schema update that changes parent_type while records exist is blocked with a 422.

Supero Platform teamSupero team answered
Link

Your answer

Coming from Firestore: how do I model subcollections? | Supero Community