Say I have two queries in a compound query. Say the potential results exceed the query limit. How does Parse prioritize which query should fill up the result first?
Does it use the first query and fill up as much as possible then move onto the next query until it hits the limit?
PFQuery *lotsOfWins = [PFQuery queryWithClassName:#"Player"];
[lotsOfWins whereKey:#"wins" greaterThan:#150];
PFQuery *fewWins = [PFQuery queryWithClassName:#"Player"];
[fewWins whereKey:#"wins" lessThan:#5];
PFQuery *query = [PFQuery orQueryWithSubqueries:#[fewWins,lotsOfWins]];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
}];
So in this case if the table "Player" has 2000 entries and the query limit is 1000 which query has priority? "fewWins" or "lotsOfWins" ?
Related
If I have pointers to multiple _User objects in an array, can i query for a value of a User.
Ex.
I have a class Groups with an array members.
members = [user1, user2, user3].
Can I do something like:
PFQuery *query = [PFQuery queryWithClassName:#"Groups"];
[query whereKey:#"members.name" isEqual:#"James"];
This can be accomplished with a nested query. Create an "innerQuery" to find Users matching the criteria. Then constrain a Group query with whereKey:matchesQuery:.
PFQuery *innerQuery = [PFUser query];
// note that referring to the "name" field only makes sense if you've
// added a name field to User (you might mean username here)...
[innerQuery whereKey:#"name" isEqual:#"James"];
// now the main query is setup to match the innerQuery
PFQuery *query = [PFQuery queryWithClassName:#"Groups"];
[query whereKey:#"members" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
}];
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.
This pointer value is pointing to _User. Later I need only rows for currUser.
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:
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);
}
}
}];
I am trying to parse some objects from my data base. I'm using parse.com as web service.
The following code gives me back some object based on 4 queries, 2 of them being compound.
The variable "meetingAge" must be equal to indexAge OR "6"
The variable "meetingSex" must be equal to "sex" OR "2"
The variable "isAvaiable" must be equal to YES
The variable "author" must be different from user.username
Basically i am trying to implement a query with 2 OR conditions and 2 AND conditions.
The following code gives me a wrong result, no exceptions or stuff like that, just a wrong kind of object. I'm sure it's a syntax issue but i can't figure out how to properly write this..If i just use 1 compound query and then add the 2 AND queries to that i get a right result, but then i miss 1 filter..
PFQuery *queryAge1 = [PFQuery queryWithClassName:#"MeetingObject"];
[queryAge1 whereKey:#"meetingAge" equalTo:indexAge ];
PFQuery *queryAge2 = [PFQuery queryWithClassName:#"MeetingObject"];
[queryAge2 whereKey:#"meetingAge" equalTo:#"6"];
PFQuery *queryCompound = [PFQuery orQueryWithSubqueries:#[queryAge1,queryAge2]];
PFQuery *querySex1 = [PFQuery queryWithClassName:#"MeetingObject"];
[querySex1 whereKey:#"meetingSex" equalTo:user[#"sex"]];
PFQuery *querySex2 = [PFQuery queryWithClassName:#"MeetingObject"];
[querySex2 whereKey:#"meetingSex" equalTo:#"2"];
queryCompound = [PFQuery orQueryWithSubqueries:#[querySex1,querySex2]];
[queryCompound whereKey:#"isAvaiable" equalTo:[NSNumber numberWithBool:YES]];
[queryCompound whereKey:#"author" notEqualTo:user.username];
[queryCompound findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
}
In your line... queryCompound = [PFQuery orQueryWithSubqueries:#[querySex1,querySex2]]; you are creating a brand new query ignoring all the age stuff.
EDIT
You are overcomplicating this.
You can do this this way...
PFQuery *query = [PFQuery queryWithClassName:#"MeetingObject"];
[query whereKey:#"meetingAge" containedIn:#[#"6", indexAge]];
[query whereKey:#"meetingSex" containedIn:#[#"2", user[#"sex"]]];
[query whereKey:#"isAvaiable" equalTo:[NSNumber numberWithBool:YES]];
[query whereKey:#"author" notEqualTo:user.username];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
}
This will catch all the options you are looking for.
Also, just as a quick note. Choose your variable names to make them more readable. If they all begin with the word query it's hard to distinguish them. Also make them descriptive. queryAge1 and queryAge2 makes it harder to understand what they are doing.
I'm trying to query to find specific users based on certain credentials.
The query will only look in the User class.
First, I want the query to match the currentUser's location
Second, must match a specific category (meaning multiple users in the same location may be under the same category)
Here's what I have tried:
self.profileObj = [self.currentUser objectForKey:#"city"];
PFQuery * queryOne = [PFUser query];
[queryOne whereKey:#"city" equalTo:self.profileObj];
PFQuery * queryTwo = [PFUser query];
[queryTwo whereKey:#"category" equalTo:self.tagString];
PFQuery * query = [PFQuery orQueryWithSubqueries:#[queryOne, queryTwo]];
[query orderByAscending:#"createdAt"];
[query findObjectsInBackgroundWithBlock:(NSArrayobjects, NSError error)
This is returning 0 results.
You don't need two separate queries since you are querying on the same User object. Also, I believe you want two AND constraints rather than OR? If so, you can just chain together two whereKeys:
PFQuery * query = [PFQuery queryWithClassName:#"User"];
[query whereKey:#"city" equalTo:self.profileObj];
[query whereKey:#"category" equalTo:self.tagString];
[query orderByAscending:#"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
...
}];
I have a join table with a from column and a to column. Both columns point to user objects. When perform this OR query, it throws the error: 'OR queries do not support sub-queries with includes'
Is there any way around this? Thanks!
// set up query to get all relationships where the current user friended another user.
PFQuery *userIsFriendSender = [PFQuery queryWithClassName:#"UserRelationships"];
[userIsFriendSender whereKey:#"from" equalTo:[PFUser currentUser]];
[userIsFriendSender whereKey:#"active" equalTo:#YES];
[userIsFriendSender includeKey:#"to"];
// set up query to get all relationships where a use friended the current user
PFQuery *userIsFriendReceiver = [PFQuery queryWithClassName:#"UserRelationships"];
[userIsFriendReceiver whereKey:#"to" equalTo:[PFUser currentUser]];
[userIsFriendReceiver whereKey:#"active" equalTo:#YES];
[userIsFriendReceiver includeKey:#"from"];
PFQuery *query = [PFQuery orQueryWithSubqueries:#[userIsFriendSender, userIsFriendReceiver]];
Try moving includeKey: clauses to the joint query.
PFQuery *query = [PFQuery orQueryWithSubqueries:#[userIsFriendSender, userIsFriendReceiver]];
[query includeKey:#"from"];
[query includeKey:#"to"];