jonthornham
jonthornham

Reputation: 3335

Parse Query Not Returning Full Object Details

I am working on a messaging app with iOS and Parse and am having trouble with Parse queries returning object with missing parameters. Let me explain.

I have created custom user objects. The user objects called MessageUserPFObjects have a pointer field that points to a PFUser.

I also have custom message object called MessagePFObjects. The MessagePFObject has a pointer field that points to the message sender and message receiver. Both the message sender and receiver are MessageUserPFObjects.

I am creating PFUsers, MessageUserPFObjects and MessagePFObjects in Parse without any trouble. I can see all of the fields are populated in Core.

My problem comes when I query the MessagePFObjects. I am querying for any message that have a specific MessageUserPFObject as the message sender or receiver. I am returned all of the MessagePFObjects but the MessageUserPFObject for the message receiver does not have any of the properties. Here is the query, and the resulting print statement.

// Note self.currentMessageUser is a MessageUserPFObject

let predicate = NSPredicate(format: "messageSender == %@ OR messageReceiver == %@", self.currentMessageUser!, self.currentMessageUser!)

let query = MessagePFObject.queryWithPredicate(predicate)

query!.findObjectsInBackgroundWithBlock ({ (result, error) -> Void in

    if result!.count > 0
    {
        for element in result!
        {
            let tempMessage = element as! MessagePFObject
            print("I am printing the messageSender returned from Parse \(tempMessage.messageSender)")
            print("I am printing the messageReceiver returned from Parse \(tempMessage.messageReceiver)")
        }
}

Print Results

I am printing the messageSender returned from Parse { accountClaimed = 1; firstName = Tom; lastName = Hanson; numberOfMessagesReceived = 0; numberOfMessagesSent = 0; messageUser = ""; }

I am printing the messageReceiver returned from Parse { }

Any help would be greatly appreciated.

Upvotes: 0

Views: 403

Answers (1)

Peter Fennema
Peter Fennema

Reputation: 1690

Add this to your query to make sure that the user objects are included in the fetch from Parse

query.includeKey("messageSender")
query.includeKey("messageReceiver")

Upvotes: 2

Related Questions