2

I'm currently saving an object into a class in Parse which currently works fine. Up to now this has mostly been flat data or the odd pointer which i'm comfortable with.

However, I've recently created a relation column is linked to a Child class which consists of a String and 2 pointers. This data will be provided at the same time as the main row is created.

In theory:

Post data from form to php to process - before saving the main object, create a new ParseObject for the relation providing the String data and associativeArray pointer id's.

Is this the correct way to do it? I have a strange feeling that i will need to save the main row before adding the relation?

Any help would be appreciated greatly :)

1 Answer 1

1

You will need to save the main row before adding the relation, because the relation relies on a reference, which relies on an objectId, which doesn't exist until after the initial save. I'm unfamiliar with PHP, though would recommend you add this relation in the success handler of the save call, if there's an equivalent. If there isn't an equivalent, it may be better to write a cloud code function in js to do this, so you can utilize promises / callbacks, and pass the data you have to that function instead of saving the object on your PHP client.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Jake, thanks for the advice - it's as i thought it would be. Going to try shifting that code over. Appreciate the help :)
One more thing @jake The relation row has 2 pointers and 1 string. If i were to create the row at the same time of the main object being saved before linking the relation, does that mean i will need to also save the relation row first and then enter add the relation?
I think those relations work slightly differently because they're a Parse default class. They handle stuff under the hood when you create a relation and attach it to an object. There is some basic info on how to use them in the parse guide: docs.parseplatform.org/js/guide/#using-parse-relations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.