Example: CRM System
Let's say you want to build a CRM system and you want to store files for customers. This is one way how you could do that.
Start with, you would have two tables:
customers
- Customer data.customer_files
- What file belongs to what customer
- customers
- id
- name
- address
customer_files
- id
- customer_id (Foreign Key to `customers.id`)
- file_id (Foreign Key to `storage.files.id`)
You would also create a Hasura Relationship (GraphQL relationship) between between customers
and customer_files
and between customer_files
and storage.files
.
With the two tables and GraphQL relationships in place, you can query customers and the customer's files like this:
query {
customers {
# customers table
id
name
customer_files {
# customer_files table
id
file {
# storage.files table
id
name
size
mimeType
}
}
}
}
The file upload process would be as follows:
- Upload a file.
- Get the returned file id.
- Insert (GraphQL Mutation) the file
id
and the customer'sid
into thecustomer_files
table.
This would allow you to upload and download files belonging to specific customers in your CRM system.