I want what ever I can have quite frankly… What I mean is when I check the autoLoad on the column ‘usersSaleItems’ in the ‘backendlessUser’ class which has a relation to the ‘usersItems’ class, what does it actually give me?
Does it just give me the objectId’s of the objects or does it give me the actual objects? either way how do I do this using the userService as in the API Docs I only see a relation function for GEOpoints? I can find no way to add-in queryOptions and have the userService ‘find’ with ‘queryOptions’.
I can for say another class using the ‘persistenceService’ it gives me all options but not the same as ‘userService’ API.
<It gave me the BackendlessUser class objects then>
), query: <BackendlessDataQuery> -> properties: (null), whereClause: (null), queryOptions: <QueryOptions> -> {
Here is ViewController.swift from my test project:
import UIKit
class Address : NSObject {
var street : NSString?
var city: NSString?
var state : NSString?
}
class ViewController: UIViewController {
let backendless = Backendless.sharedInstance()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//registerUserSync()
loginUser()
}
func registerUserSync() {
Types.tryblock({ () -> Void in
let address = Address()
address.street = "123 Main St"
address.city = "Dallas"
address.state = "Texas"
let user = BackendlessUser()
user.email = "spiday@backendless.com"
user.password = "greeng0blin"
user.setProperty("address", object: address)
let registeredUser = self.backendless.userService.registering(user)
print("User has been registered: \(registeredUser)")
},
catchblock: { (exception) -> Void in
print("Server reported an error: \(exception as! Fault)")
}
)
}
func loginUser() {
Types.tryblock({ () -> Void in
let registeredUser = self.backendless.userService.login("spiday@backendless.com", password: "greeng0blin")
print("User has been logged in (SYNC): \(registeredUser)")
let address = self.backendless.userService.currentUser.getProperty("address") as! Address
print("Autoloded Address object is in currentUser: \(address.street), \(address.city), \(address.state)")
self.backendless.userService.logout()
},
catchblock: { (exception) -> Void in
print("Server reported an error: \(exception as! Fault)")
})
}
}
I switched on the ‘autoload’ checkbox for 1:1 ‘address’ relation, then I commented line 19 and uncommented line 20, built and run my app, and got this result in a log: http://support.backendless.com/public/attachments/f8ad87b745cc641cf4b0436f58d6a48d.png</img>
So, due to checked ‘autoload’ checkbox my currentUser object has whole Address object in its ‘address’ property (1:1 relation)
This scenario also works for me (in context of example with 1:N relation user property below in this thread):
func singleStepRetrieval() {
let dataQuery = BackendlessDataQuery()
let queryOptions = QueryOptions()
queryOptions.related = ["address"];
dataQuery.queryOptions = queryOptions
var error: Fault?
let bc = backendless.data.of(BackendlessUser.ofClass()).find(dataQuery, fault: &error)
if error == nil {
print("Users have been found: \(bc.data)")
let users = bc.data as! [BackendlessUser]
for user in users {
let addresses = user.getProperty("address") as! [Address]
for address in addresses {
print("'\(user.email) user address object is: \(address.street), \(address.city), \(address.state)")
}
}
}
else {
print("Server reported an error: \(error)")
}
}
now I get ‘usersSaleItems’ = ("<saleItems: 0x7fa6e3d4d2a0>") which is cool, however! What is it!? Is it an NSObject a dictionary an array or simply is it the objectId of the linked item therefore I need to run a dataQuery method to get it?
Either way what is the line of code I need to write to extract this information. this is what I can’t seem to see…
I sudden realised that the one-to-many relations wasn’t working when I was only seeing 1 object in the ‘usersSaleItems’ results. When I looked at the data base GUI I realised that only the latest object was holding the link. Am I missing a line of code here?
Steve, in your code you have set saleItemUpload object of ‘saleItems’ class as “usersSaleItems” user property:
[user setProperty:@“usersSaleItems” object: saleItemUpload];
i.e. you create 1:1 relation, so
saleItems *item = [user getProperty:@“usersSaleItems” ];
you will get item object of ‘saleItems’ class, and you can use this object and its properties.
The rule working with user property: “what you have set, than you will get”.
If you need 1:N relation - you need:
[user setProperty:@“usersSaleItems” object: @[saleItemUpload]];
then:
NSArray<saleItems*> *items = [user getProperty:@“usersSaleItems” ];
I am now able to extract all the information from the collection so, once again a BIG thanks to you all.
I know I have said it before but:
Backendless Support verse Parse Support ----- There is no competition! Backendless wins hands down! in fact your support is super amazing and really responsive and I WISH I found Backendless before I even tied myself with Parse, I really do.
If you need to get array which is contained in BackendlessCollection object, you can use its method:
-(NSArray *)getCurrentPage;
So, for your purpose:
NSArray *arrayOfCollection = [[collection getPage:1] getCurrentPage];
or, in a context of your sample, simply: