Relational Schema
This guide explains how to work with relational schemas on Back4app, including creating related classes and performing efficient queries using Parse Server. You will learn how to use Pointers and Relations effectively, along with practical examples.
A relational schema organizes data into different classes connected to each other. In Parse Server, these relationships are managed through:
- Pointers: Refer directly to a single object.
- Relations: Manage multiple connections (many-to-many relationships).
These tools allow you to perform complex queries efficiently and consistently.
By the end of this guide, you will be able to:
- Create relationships between classes using Pointers and Relations.
- Perform relational queries to retrieve connected data.
- Optimize your schema for better performance.
Imagine you want to model a system where cities are associated with states:
- Class State with the field state_name.
- Class City with the field city_name and a Pointer to State.
Now that the data is related, you can perform queries to retrieve it.
Create a query that returns states connected to any city:
To effectively work with relational schemas using Parse Server in Back4App, follow these best practices to ensure performance, maintainability, and scalability:
- Use Pointers for one-to-one relationships, such as linking a user to their profile.
- Use Relations for many-to-many relationships, such as linking a project to multiple tasks.
- Use .include() to load related data in the same query, reducing the need for multiple requests.
- Limit results using limit() and skip() to avoid fetching large datasets at once.
- Index frequently queried fields to speed up searches.
- Keep queries flat to reduce complexity and improve performance. Use nested queries sparingly and only when necessary.
- For complex queries involving multiple relations or large datasets, offload these to Cloud Code to keep the client lightweight and responsive.
In this guide, you learned how to create relationships between classes and query-related objects on Back4app. Continue exploring the specific SDK documentation to dive even deeper!