I’m using User table with two relationships:
http://support.backendless.com/public/attachments/722e8c9544135788abac702fe099d5db.png</img>
I’m trying to get the user with the relationships, using Persistence Service:
Backendless.sharedInstance().persistenceService.findById("BackendlessUser", sid:objectId, relations: ["contacts", "potentialContacts"], relationsDepth: 3, response: { (user: AnyObject!) -> Void in
success?(user as! BackendlessUser)
}) { (fault: Fault!) -> Void in
let err = NSError(domain: fault.message, code: (fault.faultCode as NSString).integerValue, userInfo: nil)
failure?(err)
}
doesn’t return relations, although I’ve specified them correctly and provided relationshipDepth as well
Using User Service
let user = Backendless.sharedInstance().userService.findById(objectId)
doesn’t return relations either
Any idea what I may be doing wrong?
P.S.: I don’t want to autoload the relationships, because I don’t always use them.
Could you provide your PotentialUser class and your appId here or to support@backendless.com
Hi Miroslav,
I just created a sample project with your class (see in attachment). It fetches BackendlessUser object by Id with you func above.
Here is users with 1:N ‘contacts’ relation and 1:1 ‘potentialContact’ relation (without autoload):
http://support.backendless.com/public/attachments/c4f12ff6a7b61390dab117dcded1b18f.png</img>
and a log:
http://support.backendless.com/public/attachments/6b408e14e1e400161e85173c48c734be.png</img>
As you can see: both relations are in fetched BackendlessUser object.
You could try my project (it uses pod ‘Backendless’ 3.0.23, so you should load it using TestPotentialUser.xcworkspace).
Then change appId & secretKey to yours, and try with your Backendless app.
Please let me know how it goes for you.
Regards,
Slava
TestPotentialUser.zip (19.26MB)
Hi Slava,
the problem was in BackendlessUser extension I had. One does not simply subclass or extend a BackendlessUser:)
What you need to do is to be creative when defining the methods. Don’t use properties, don’t use setContacts and getContacts method names.
giveMeContacts works fine:)
extension BackendlessUser {
var phoneNumber : String? {
get {
return self.getProperty("phoneNumber") as? String
}
set {
self.setProperty("phoneNumber", object: newValue)
}
}
func giveMePotentialContacts() -> [PotentialUser]? {
return self.getProperty("potentialContacts") as? [PotentialUser]
}
func giveMeContacts() -> [BackendlessUser]? {
return self.getProperty("contacts") as? [BackendlessUser]
}
// Derived Values
func isUser() -> Bool {
return self.objectId == NetworkService.sharedInstance.currentUser.objectId
}
}
Thanks anyway!
You shouldn’t extend or inherit BackendlessUser class.