This is a migrated thread and some comments may be shown as answers.

Expanding relation to Users

3 Answers 54 Views
Android SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Viktor
Top achievements
Rank 1
Viktor asked on 06 Oct 2017, 07:26 AM

Hi,

I have a content type for Comments and every comment has additional field called "UserId" which is relation to Users. I have also added some fields to Users content type, therefore I have extended the "User" class from Android SDK to "MyUser". This is how my classes look basically:

^^^^^

ServerType("Comments")
public class Comment extends DataItem {
   @ServerProperty("UserId")
   private UUID userId;

   @ServerProperty("UserData")
   private MyUser user;

^^^^^

@ServerType("Users")
public class MyUser extends User {
   @ServerProperty("Picture")
   String pictureUrl;

^^^^^

And the expand definition is like this:   ExpandDefinition expandDefinition = new ExpandDefinition("UserId", "UserData");

 

The result is that "UserData" has all properties with NULL as a value. If I change the type of "UserData" to the default class "Users", the data is populated, by then I'm missing the user's picture.

 

How should this be done?

 

Thanks,

Viktor

 

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 10 Oct 2017, 09:48 AM

Hi Viktor,

Sorry for the delayed response.

From the provided description the expand expression and model classes should all be set fine. I tested on my side with the provided information and the extended class MyUser fields populate just fine.

Could you please provide a sample project in order to test on my side as well?

You may also add an afterRead Cloud Code for data event to the Comments content type to check what is the response returned from the server:

Everlive.Events.afterRead(function(request, response, context, done) {
    console.log(JSON.stringify(response));
    done();
});

Waiting forward for your reply.

Regards,
Martin
Progress Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Viktor
Top achievements
Rank 1
answered on 10 Oct 2017, 10:42 AM

Hi Martin,

When request is executed from POSTMAN or Web, the data is fine and everything is there. My suspicion is that it has to do something with parsing the result (i.e. in Android SDK). In my previous post I've described what what the schema is like and this is everything needed.

 

Thanks,

0
Martin
Telerik team
answered on 10 Oct 2017, 03:09 PM
Hi Viktor,

I have used the described schema and modified slightly this sample app to test the case on my side and the custom MyUser class property get populated just fine when using an expand expression. I have attached the project I tested with.

Please test this on your side as well - you may login with user "123", password "123".

In model/Post.java I have added:
@ServerProperty("UserData")
private MyUser UserData1;

In activities/ListActivity.java, in loadPosts() method I have added the expand expression and you may see that the returned  ArrayList<Post> posts have the expanded MyUser object populated.

Let me know if this is working on your side as well and if this has helped.

Regards,
Martin
Progress Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
Android SDK
Asked by
Viktor
Top achievements
Rank 1
Answers by
Martin
Telerik team
Viktor
Top achievements
Rank 1
Share this question
or