Reputation: 8114
I have an application which uses parse as database and has following tables.
User Table: Provided as default class by parse additionally it has user skills, user address, myJobs (which is an array of object ids of Job Class, the jobs that I have posted.), myAppliedJobs (which is an array of object ids of AppliedJob Class, the jobs I have applied).
Job Table: The table to hold job data like job name, desired skills, job location etc.
AppliedJob: Which has a mapping between user and job via pointers plus some additional information like notes, wage change.
Now, In a screen I list all the jobs that I have posted. Which I can get easily with the array of my jobs. But that costs me an extra call to do fetch if needed.
Then I have an option to view all the applicants that have applied to my job, which I do by querying applied jobs class with help of jobid to get applied job objects array. Now with the help of this array I get all user ids and fetch them via fetch all in background.
This is adding to calls per second which is my prime objective to reduce. Please give me some insight.
Upvotes: 0
Views: 110
Reputation: 9942
First try to envision the kinds of queries you will perform, and then design your schema around that. I would recommend thinking more in terms of NoSQL queries rather than SQL queries (and schema).
In your case, you could easily avoid expensive queries if you added a new column to your Job table, called Applicants. This is just an Array of pointers to all AppliedJob records that have applied for the job. When saving a job application, you update this array as well (preferably in an afterSave hook in cloud code).
Then, when fetching a Job record, you use [includeKey: @"Applicants"];
and all AppliedJob records are fetched for you with your Job.
Upvotes: 2