Reputation: 53
I'm using the parse backend to be database of my apps in Xcode (objective-c), but I don't know how to write a multiple condition parse format query. I want to convert the below query to a parse format query in the Xcode.
$msg_record = $this->db->query('SELECT msg, send_id, send_time FROM msg_record
WHERE (send_id=123456789 AND to_id=987654321) OR (send_id=987654321 AND to_id=123456789)
ORDER BY send_time ASC')->result();
Can anybody help me to convert the query? Thanks.
Upvotes: 3
Views: 764
Reputation: 968
To create an or condition in a Parse query, you will have to make two (or more) subqueries which you merge with the orQueryWithSubqueries
.
Be aware that you cannot translate SELECT
directly from SQL to Parse.
This is what you are looking for:
PFQuery *query1 = [PFQuery queryWithClassName:@"msg_record"];
[query1 whereKey:@"send_id" equalTo:@"123456789"];
[query1 whereKey:@"to_id" equalTo:@"987654321"];
PFQuery *query2 = [PFQuery queryWithClassName:@"msg_record"];
[query2 whereKey:@"send_id" equalTo:@"987654321"];
[query2 whereKey:@"to_id" equalTo:@"123456789"];
PFQuery *mainQuery = [PFQuery orQueryWithSubqueries:@[query1,query2]];
[mainQuery orderByAscending:@"send_time"];
Upvotes: 5