Relationships
Link documents across collections with a relationship attribute, then expand the related
documents on read with populate.
Define a relationship
Create relationship attribute
curl -X POST "https://base.finiteskills.com/v1/databases/main/collections/books/attributes/relationship" \
-H "X-Appwrite-Project: <YOUR_PROJECT_ID>" -H "X-Appwrite-Key: <API_KEY>" \
-H "Content-Type: application/json" \
-d '{"key":"author","relatedCollection":"authors","type":"manyToOne"}'
Types: oneToOne, oneToMany, manyToOne, manyToMany. In a
document, a to-one relationship stores the related id; a to-many stores an array of ids.
Expand on read
populate
# returns the full author document(s) inline instead of just ids
GET /databases/main/collections/books/documents/hobbit?populate=author
GET /databases/main/collections/books/documents?populate=author
Relationships are resolved in one query per related collection (no N+1). This is FiniteBase's join model over the document store.