Search code examples
iosswiftherokuparse-platform

Parse.com - email from PFUser object fetches a nil despite having value


I have a query "items" object. The class has a "parent" key that points to _User object.

The query is successful and fetches 'parent' object and i am able to access some custom keys from this 'parent' object but email is returned as nil !! below is stripped down code.

Could anyone suggest why is this happening? This was working earlier and i have not made any code change. Running Parse-server ver 2.5.3 on Heroku.

     let query = PFQuery(className: "items")
     query.includeKey("parent") // parent points to _User


     do {

         let results = try query.findObjects()

         for result in results {

         let parent = result["parent"] as! PFUser

        let foundUser = User()
        foundUser.user = parent // User.user is of PFUser type

        //custom keys in _User
        foundUser.name = parent["name"] as! String 
        foundUser.city = parent["city"] as! String
        foundUser.geoLocation = parent["location_geopoint"] as! PFGeoPoint 
        foundUser.userAddress = parent["user_address"] as! String

        //this is failing with nil eventhough there is value in Parse
        foundUser.email = parent["email"] as! String

        // also tried this. parent.objectId returns a valid value
        foundUser.email = parent.email


       }

     } catch...

Solution

  • Got the answer here enter link description here

    In 2.3.0 there was a breaking change introduced which restricted the fields returned from a query on _User. If I remember correctly, email is taken out by default and you can specify additional fields to be removed from a query result in a configuration setting. In order to retrieve email you either have to specify the master key or be the owner of that object.