I am showing some posts (created by the users) in an activity using a custom adapter. In the constructor of the custom adapter, I am using the following code to get the query result.
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereGreaterThan("expire_date", new Date());
return query;
The target is - the user can set an expire date with each post so that the post will no longer be visible after the expiration. I am trying to compare the expire_date column with current time for checking if the post is expired or not.
The line query.whereGreaterThan("expire_date", new Date());
was added later. All the previously created rows has a null value in the expire_date column.
So each time I run the query, all the rows that has a date object in expire_date column are being checked according to the condition. The rows having a null value in expire_date column are never returned .
Note: The expire_date column is not a mandatory field (user can choose to leave it empty during creating a post).
Yes, I can set a default date for all the empty/null fields to compare with the expire date. But I was curious to know if there is a way so that I can either return all the rows having a null value or compare the current time with a null object with the whereGreaterThan
condition?
ParseQuery notExpiredPosts = new ParseQuery("Post");
query.whereGreaterThan("expire_date", new Date());
ParseQuery noExpiredDate = new ParseQuery("Post");
query.doesNotExist("expire_date");
ParseQuery expiredDateQuery = ParseQuery.or(notExpiredPosts, noExpiredDate);
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereMatchesKeyInQuery("objectId", "objectId", expiredDateQuery);
return query;
[(NotExpiredPost || NoExpiredDate) & (location_point within 500 mile)]
This is what you want, isn't it?
Hope this helps :)
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.