0

I have two tables A & B, in table B I have a column of type pointer, each field points to a class in table A.

I need to know how to query table B based on the value of a particular field in the pointer column.

So for example, I have 4 objects (records) in table B, and in the pointer column I have pointer1, pointer2, pointer3 and pointer4. So if I want to carry out a query on table B and I want to extract the record with the field value of pointer3 how do I do this in javascript?

2
  • You question doesn't quite make sense, do you mean you want to query records from TableB where TableB.pointer3 = pointerA, where pointerA is some known value? Commented Jun 17, 2014 at 3:48
  • I have two tables, A and B, in B there is a pointer column that points to A. I populate a html table with both of these tables using the pointer column. My user can edit the html table row, so when they click save I need to update both parse tables (A & B) with data from the html table fields. So I was thinking of updating one then on success update the other or would you have a better method? Commented Jun 17, 2014 at 8:50

2 Answers 2

1

Based on your comment I would suggest storing both object IDs for each row. You could use Parse.when(recordA.save(), recordB.save()).then(...) to wait until both finished if you needed to provide feedback in the UI.

An alternative is to just store the object ID for the table B record and in the success handler you'll get back the updated record that'll include the pointer where you can then execute another save. This is slow as it will do two saves in sequence instead of kicking both off at once.

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

1 Comment

Thanks for your quick reply Timothy, I'm quite new to parse, would you be able to show a sample? I've got this far slogging through the docs and forums but I'm truly at a juncture and I'm not sure how to proceed. thanks
0

So after a long time searching and looking around and asking questions I figured it out myself in the end. I needed to pass in an object in the query.equalTo method like so:

query.find({
        success: function(results) {

        var detailsObject = results[0];
        detailsObject.set("uuid", uuid);
        detailsObject.set("proximity", prox);
        detailsObject.set("campaignId", campaignId);
        detailsObject.set("location", location);
        detailsObject.set("sub_location", subLoc);

        detailsObject.save(null, {
            success: function(detailsObject) {

                var content = Parse.Object.extend("Content");
                var contentQuery = new Parse.Query(content);
                var id = detailsObject.id;
                contentQuery.equalTo("descId", detailsObject);

So "descId" is the pointer column in my content table and rather than trying to query the value in the field (object id of details object), I needed to pass the details object into the query.equalTo

I hope this is of benefit to someone else.

Comments

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.