1

I am designing a database. According to documentation, when number of relationships are greater than 100 and there is extra fields, I must design a Join Table. I designed this Join Table by having two pointer value.

  1. This pointer value is pointing to _User. Later I need only rows for currUser.
  2. This pointer value is the objectId of another table which is an entity. My question is, how can I write a query to return objects for this table in queryfortable.

Let's say:

Table _User
Table Entity
Table Join ---> objectId   Pointer1(_User)  Pointer2(Event)

This look like this:

enter image description here

This is what I have tried so far:

First I tried in viewDidLoad to get array of invitedUser from cloud and later in queryForTable:

    PFQuery *query = [PFQuery queryWithClassName:@"Event"];
    [query whereKey:@"objectId" containedIn:_inviteList];

but I need to access _inviteList.objectId which is not possible!

I tried to use innerQuerry or relation query. but as I just started learning parse I am not able to implement this.

PFUser *friendPointer = [PFUser currentUser];
PFQuery *query2 =  [PFQuery queryWithClassName:@"Event"];
[query2 whereKey:friendPointer containedIn:_inviteList];
return query2;

This also did not work for me.

    PFQuery *innerQuery = [PFQuery queryWithClassName:@"Invite"];
    [innerQuery whereKey:@"invitedUser" equalTo:[PFUser currentUser]];

    query = [PFQuery queryWithClassName:@"Event"];
    [query whereKey:@"user" matchesQuery:innerQuery];
    return query;

I appreciate if anyone can help me to write this query or re-design my table in order to have access to this query.

1 Answer 1

3

Pleaser try this code and give me review

PFUser *user = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@"Invite"];
[query whereKey:@"invitedUser" equalTo:user];
[query includeKey:@"invitedUser"];
[query includeKey:@"eventId"];
[query orderByDescending:@"updatedAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
 {
     if (error == nil)
     {
         for (PFObject *underobject in [objects reverseObjectEnumerator])
         {
             PFUser *user1 = underobject[@"invitedUser"];
             NSLog(@"invitedUser is :%@",user1);
         }
     }
}];
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.