I have a problem!!!
I have 2 tables, one is Item and the other is Users(table system). There is one relationship between 2 tables, each Item has 1 owner(a Users object) so i created a relationship in Item table, i call it ‘owner’ relationship.Now i have a new item, and i want currentUser is the owner of that item, the code below i tried but i didn’t work:
id <IDataStore> items = [backendless.persistenceService of:[GSItem class]];
BackendlessUser *currentUser = [backendless.userService currentUser];
GSItem *newItem = [[GSItem alloc] initWithName:self.name andFrom:self.fromLabel.text andTo:self.toLabel.text andInfo:self.info andStatus:0 andFee:self.fee andOwner:currentUser];
[items save:newItem response:^(id response) {
[hud hideAnimated:YES];
NSLog(@“Added a new item successfully !”);
NSLog(@"%@",response);
//Navigate to Searching Shipper Screen
}error:^(Fault *error) {
NSLog(@"%@",error.message);
}];
The error was : Cannot save entity with primitive collection property
How can i save a relationship ???
Please repond soon.
Looks like you try to save the GSItem object which contains an empty array (1:N relation).
Could you provide your GSItem class - here or to support@backendless.com?
It’s a 1:1 relationship between a GSItem object and Users(table system).
This is my GSItem class:
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *from;
@property (nonatomic, strong) NSString *to;
@property (nonatomic, strong) NSString *info;
@property (nonatomic) NSInteger status;
@property (nonatomic) NSString *fee;
@property(nonatomic, strong) BackendlessUser *owner;
Please email your GSItem class to support@backendless.com
You should use NSNumber for all numeric and boolean properties, so please change:
@property (nonatomic, strong) NSNumber *status;
and make an associated refactoring of your implementation.