Search code examples
iosswiftparse-server

Parse query with a wherekey on a pointed to object


I am trying to create a query where I can check if the value of an object pointed to meets a certain requirement. Example I have a class called rooms, each room object has a pointer to a post object. I want to check wherekey updatedAt of the post object when getting rooms.

I have tried doing this query.whereKey("post.updatedAt", greaterThan: timeThen!)

but it returns empty


Solution

  • You should use relational query so you have to make a query for posts first

    let postsQuery = PFQuery(className:"Post")
    query.whereKey("updatedAt", greaterThan: timeThen!)
    

    and then compose the query with the postsQuery like this:

    query.whereKey("post", matchesQuery query: postsQuery)
    

    here is the link for the parse guide.