Does backendless.userService have a relations functions?

I am getting myself in a pickle and here is why: I created a class called ‘saleItems’ with a column called ‘seller’ and ‘seller’ has a relation to the backendlessUser class. In the backendlessUser class I see a new column called ‘saleItem.seller’ which is cool and I can see all the object ID’s in the ‘saleItems’ class linked to the backendlessUser.
Now! can I ‘retrieve’ the currentUser details WITH all the saleItems that are linked to the user using the userService OR do I have to do it the other way round by creating a backendless.dataquery on the ‘saleItems’ class in which EVERY object will be retrieved with the user details , which seems a bit silly!?!?!?!?
Like I said my brain is all a pickle over this so if you can steer me in the right vain that would be awesome!
Take care

Hi Steve,

“saleiItem.seller” is not a column in the schema sense. There is no such property in the BackendlessUser object. It is nothing more but a visualization that any given user is “a child of” (that’s the precise term used in console) of some other object.

Columns (and thus properties) exist in the tables where you define them. If you define a custom property in BackendlessUser, it will belong to the user object. If you define a column (and thus a property) in SaleItems, that’s where it will exist.

Does it help?


hmmm… so can I create column in the BackendlessUser class thats linked to the ‘saleItems’ class so that all I need to do is retrieve the user with a .related option?

Would that work?


cool! now lets try it. Thanks Mark!

Mark. so I created the relationship in a column in the backendlessUser Class now when I save an object in the ‘saleItems’ class do I also have to add the objectID into the backendlessUser Class or is there some magic?

No, just add the object (or a collection of) using the setProperty method in BackendlessUser and then save the user object - the related will be created/updated automatically. Make sure to verify it with the console.

wow! ok I will try it now

hmmm… I have the class ‘saleItems’ and I create a new object but then I tried to save it against the backendlessUser Class and it crashed. I think I am missing a line of code somewhere…

saleItems *saleItemUpload = [saleItems new];

saleItemUpload.itemTitle = itemTitle.text;

saleItemUpload.itemDescription = descriptionUITextView.text;

saleItemUpload.itemURLA = itemURLA;

saleItemUpload.itemURLB = itemURLB;

NSNumber *number;

number = @([pandaPoundsValue.text intValue]);

saleItemUpload.itemPPCost = number;

saleItemUpload.seller= [backendless.userService currentUser];

BackendlessUser *user = backendless.userService.currentUser;

[user updateProperties:@{@"saleItems" : saleItemUpload}];

user = [backendless.userService update:user];

Instead of this:

[user updateProperties:@{@“saleItems” : saleItemUpload}];

try this:

[user setProperty:@“saleItems” object: saleItemUpload];

Thanks. I tried it but didn’t like it. crashed and through this error:

warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.


Try to comment:

//saleItemUpload.seller= [backendless.userService currentUser];

Yes that was it! Must of made the database crazy or something.

Thanks Backendless TEAM!

I have noticed actually that when trying to run a query against a column that has a relation to a userID it will say the column doesn’t exist.

here is a small piece of code but the column is there yet I get a doesn’t exit response!

BackendlessDataQuery *dataQuery = [BackendlessDataQuery query];

dataQuery.whereClause = @"seller = 'userID'";

Responder *responder = [Responder responder:self selResponseHandler:@selector(responseHandler:) selErrorHandler:@selector(errorHandler:)];

[backendless.persistenceService find:[saleItems class] dataQuery:dataQuery responder:responder];

Is “seller” a relation column?


then the whereClause must be formed like this:

dataQuery.whereClause = @"seller.objectId = 'userID'";

assuming that you do not put “userID” literally there… It should be a valid objectId value…

ah ok! So, I was doing this because of the original topic here so now the I am saving ‘saleItems’ through the backendlessUser class, how do I retrieve these with the userService?

Do I do this:

BackendlessUser *user = backendless.userService.currentUser;
NSArray *arrayOfSaleItems = [user getProperty:@“saleItems”];

I can see them in the user object but they just look like this:

saleItems = “<saleItems: 0x14dd45050>”;

just an object ID… but how to get the whole object?

If you have set ‘saleItems’ object as user property - why you would like to get an array?

I see you got saleItems object (whole), so you can use its properties as well.