With reference to
http://strongloop.com/strongblog/defining-and-mapping-data-relations-with-loopback-connected-models/
if I have defined a relationship between a customer and an order so that an order belongsTo a customer, how can I get the customer details from the order using the iOS SDK? I'm currently using invokeStaticMethod to get a filtered list, like this:
func getOrders() {
var prototype: LBModelRepository = adapter.repositoryWithModelName("orders")
adapter.contract.addItem(SLRESTContractItem(pattern: "/orders", verb: "GET"), forMethod: "orders.filter")
var params = [
"filter[where][customerId]": "\(self.customerId)",
"filter[order]": "startDate DESC"
]
var success: SLSuccessBlock = {
(results: AnyObject!) in
var resultsArray = results as NSArray
var resultsMutableArray: NSMutableArray = NSMutableArray()
for result: AnyObject in resultsArray {
resultsMutableArray.addObject(result as NSDictionary)
}
self.tableData = resultsMutableArray
self.tableView.reloadData()
}
var failure: SLFailureBlock = {
(error: NSError!) -> () in
}
prototype.invokeStaticMethod("filter", parameters: params, success: success, failure: failure)
}
Is it something to do with calling invokeInstanceMethod with a method name of "orders.prototype.customer"? How can I combine the calls efficiently?
You can probably use the include parameter to embed the included relations. See more information at http://docs.strongloop.com/display/LB/Include+filter.