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.
_User
. Later I need only rows for currUser
. 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:
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.
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);
}
}
}];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.