2015-11-09 15 views
7

Tôi đang cố truy vấn tất cả người dùng hiện tại trong ứng dụng của mình mà người dùng chưa thêm làm "Bạn bè". Tôi nhận được lỗi'Không thể thực hiện truy vấn so sánh cho loại: PFRelation' Swift

Không thể làm một truy vấn so sánh cho loại hình: PFRelation

Dưới đây là mã hiện tại của tôi:

override func queryForTable() -> PFQuery { 

    let currentFriends : PFRelation = PFUser.currentUser()!.relationForKey("friends") 

    // Start the query object 
    let query = PFQuery(className: "_User") 
    query.whereKey("username", notEqualTo: currentFriends) 

    // Add a where clause if there is a search criteria 
    if UserInput.text != "" { 
     query.whereKey("username", containsString: UserInput.text) 
    } 

    // Order the results 
    query.orderByAscending("username") 

    // Return the qwuery object 
    return query 
} 

Làm thế nào để giải quyết vấn đề này? Cảm ơn

Trả lời

5

Tôi đã giải quyết được sự cố .... theo cách nào đó. Tôi không thể so sánh PFRelation vì vậy tôi đã tạo một lớp Parse giúp người dùng thêm người dùng khác là "từ" và người dùng họ thêm là "vào" thì tôi có thể so sánh chúng như thế này.

let currentUser = PFUser.currentUser()?.username 

    let currentFriends = PFQuery(className: "Friends") 
    currentFriends.whereKey("from", equalTo: currentUser!) 

    // Start the query object 
    let query = PFQuery(className: "_User") 
    query.whereKey("username", doesNotMatchKey: "to", inQuery: currentFriends) 

Tôi hy vọng điều này sẽ giúp ai đó trong tương lai.

Các vấn đề liên quan