Pitfall: Parse Circular Dependency Error and Bidirectional Relationship
When you save a PFObject and encounter the error Found a circular dependency when saving, it could be due to you setting a bidirectional/inverse relationship.
Take this example:
1 2 3 4 5 | |
Upon save, the code will throw the exception Found a circular dependency when saving. This is because bidirectional relationship is not supported on Parse.
The solution requires 3 steps:
- Don’t set up any of the relationship, and save
teacherfirst. Saving will provideteacher.objectId. - Then save
studentwith 1 directional relationship toteacher. Saving will providestudent.objectId. - Then update
teacherwith the relation tostudent.
This takes 3 API requests to set up.
Not good, but workaround the limitation of Parse.