1

I am trying to build a chat app in Parse using Swift. At viewDidLoad I want to query Dashboard for new messages. I do that with below code but don’t get any results and parse does not give me any error. As Parse does not know joins, how can I fetch the Chat data based on a subquery ?

My plan is to do something like this:

Select * from Chat inner join ChatMember where chat.objectId =  ChatMember.chatId and user = <current user>

Code

    let squery = PFQuery(className: "ChatMember")
    squery.whereKey(“user”, equalTo:(PFUser.current())!)


    let query = PFQuery(className: "Chat")
    query.whereKey("chatId", matchesQuery: squery)

    // tried it with this one too, but same result

    query.whereKey("objectId", matchesKey:"chatId", in: squery)

Data Structure

Class Chat {objectId: String, owner: Pointer _User, name: String,    lastActivity: Date}

Class ChatMember {objectId: String, chatId: Pointer Chat, user: Pointer _User, memberSince: Date,  lastActivity: Date, Mute: Boolean}

Class Message {objectId: String, chatId: Pointer Chat, author: Pointer _User, createAt: Date, message: String }

Tests I already did:

The fields in the database are correct. Because if I add a new column to ChatMember and store the chat id as string it works perfectly. Just not with the pointer:

let squery = PFQuery(className: "ChatMember")
squery.whereKey(“user”, equalTo:(PFUser.current())!)


let query = PFQuery(className: "Chat")
query.whereKey("objectId", matchesKey:"CHATID_AS_STRING", in: squery)
Style-127
  • 35
  • 6
  • I am having a similar issue at http://stackoverflow.com/questions/41300287/retrieving-an-array-from-parse-com. Have you figured this out? – David Sanford Dec 23 '16 at 15:34
  • One note that might help you (if you are using swift 3) is you need all of PFUser.current()!.username. You left out .username as with what you have this will not return the name, but the code – David Sanford Dec 23 '16 at 15:37

0 Answers0