1

I have a database schema which includes two tables in parse: contacts & contactRelationships.

Contacts includes a list of contacts, contactRelationships ties users together to form a relationship, i.e:

Contacts
userid: 1, username: Bob
userid: 2, username: Alice
userid: 3, username: Chris


ContactRelationships
friend_A: 1, friend_B: 2 --> Bob and Alice are friends
friend_A: 2, friend_B: 3 --> Alice and Chris are friends

I want to construct a query such as: "SELECT * FROM ContactRelationships WHERE friend_A = 1 AND friend_B = 2".

The problem I'm having right now is that in Parse, I'm storing pointers to the contacts, and I'm trying to construct a query, but I don't have the pointers stored in local data (core data). I only have the user ids stored.

Is there any way to do this without having to change the database to store userid strings instead of pointers?

1 Answer 1

4

Maybe this answer can help you with your query: Parse.com: Find all objects belonging to a user with objectId

Basically you should set your query to include the nested objects instead of bring only pointers. Than you can create your desired users objects and compare the whole objects instead of just their object ids.

I don't know which language are you programming but in Cloud Code (Javascript) the code can look like this:

// Create your query and set which nested objects you want
var query = new Parse.Query('ContactRelationships');
query.include('friend_A');
query.include('friend_B');

// Create local instances of your user objects
var userA = new Parse.User();
userA.id = 1;
var userB = new Parse.User();
userB.id = 2;

// Query your database comparing objects
query.equalTo('friend_A', fetchedUserA);
query.equalTo('friend_B', fetchedUserB);
query.find({
    success: function(result) {
        // Do your thing here
    }
});
Sign up to request clarification or add additional context in comments.

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.