Hi,
The scenario in which this problem occurs involves 3 classes:
User
Conversation
Message
User has a one-to-many relation to objects of type Conversation, let's call this 'User.conversations'
Conversation has a one-to-one relation to objects of type Message, lets's call this 'Conversation.latestMessage'
I have a CustomEventHandler that retrieves Conversation(s) for a User. Since I have set the ‘autoload’ property on the ‘Conversation.latestMessage’ ticked, I expected the Conversation objects retrieved to contain an autoloaded instance representing the ‘Converstation.latestMessage’. The field however isn’t populated when:
Object[] result = new Object[0];
try
{
Backendless.Data.of( BackendlessUser.class ).loadRelations(
p_user,
new ArrayList<String>( Arrays.asList( UserKeys.CONVERSATIONS ) )
);
result = (Object[]) p_user.getProperty( UserKeys.CONVERSATIONS );
}
catch (Exception e)
{
e.printStackTrace();
}
return result;
returns. Is this expected behaviour?
Cheers,
Grant.
Hi, Grant!
Thanks for you message.
We’ve reproduced this issue, and it’s going to be fixed in the nearest future. We shall notify you about it.
For now to retrieve the field “conversations” I can offer you the following code:
QueryOptions options = new QueryOptions();
options.setRelationsDepth( 2 );
String whereClause = "objectId = '" + p_user.getObjectId() + "'";
BackendlessDataQuery query = new BackendlessDataQuery();
query.setQueryOptions( options );
query.setWhereClause( whereClause );
BackendlessUser user = Backendless.Data.of( BackendlessUser.class ).find(query).getCurrentPage().get(0);
In this case you may not care about enabling “autoload” for property “latestMessage”.
with best regards,
Alex Navara
Thanks a lot that’s great!
Grant.