解析 - 查询嵌套指针?

时间:2015-03-29 22:08:17

标签: ios parse-platform

我试图对对象中的嵌套指针运行查询。 根据文档,当嵌套指针包含在查询中时,支持点符号,但这似乎不起作用。它没有返回state == %@ AND event.expirationDate > %@

let predicate = NSPredicate(format: "to == %@ AND (state == %@ OR (state == %@ AND event.expirationDate > %@))",
        User.currentUser(),
        EventInvitation.State.Accepted.rawValue,
        EventInvitation.State.Pending.rawValue,
        NSDate())

let query = EventInvitation.queryWithPredicate(predicate)
query.includeKey("event")
query.includeKey("from")

1 个答案:

答案 0 :(得分:0)

以下是我解决这个问题的方法

let acceptedQuery = EventInvitation.query()
    .whereKey("state", equalTo: EventInvitation.State.Accepted.rawValue)
    .whereKey("to", equalTo: User.currentUser())

let pendingQuery = EventInvitation.query()
    .whereKey("state", equalTo: EventInvitation.State.Pending.rawValue)
    .whereKey("event", matchesQuery: Event.query().whereKey("expirationDate", greaterThan: NSDate()))
    .whereKey("to", equalTo: User.currentUser())

let finalQuery = PFQuery.orQueryWithSubqueries([acceptedQuery, pendingQuery])
    .includeKey("from")
    .includeKey("event")