Entity with two relations to Users table

Hi. I have “Compra” table, that has two relationships with Users table: “dependiente” and “user”. Whenever I try to save a new “Compra” object, i get some messages in console and process never ends. It doesn´t print any errors, it just keeps running and never ends … I am really confused with this.

I have attached my “Compra” class, part of the code that is failing and also some log messages that were printed when saving the object.

¿What should be the right way to save this kind of objects? I have checked that “Compra” objects with null value in relationships “dependiente” and “user” are correctly saved. But when i assign one BackendlessUser to any of those relationships, i get the error.

Please let me know if you need more information.

backendless.txt (5.26kB)

Andres,

Do you use the latest build of the Backendless library (v. 1.10) from our site?

Regards,
Mark

Hi Mark.

I have updated to the last version from your site and now i am getting this error in a previous step, when retrieving user properties:

2014-03-24 20:10:09.341 Fidelizacion_Dependiente[4821:60b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[Users allKeys]: unrecognized selector sent to instance 0x14574330’
*** First throw call stack:
(0x3007af4b 0x3a8f16af 0x3007e8e7 0x3007d1cb 0x2ffcc4d8 0x9aa31 0x30f13 0x17cfa5 0x17caff 0x15747b 0x30a5538b 0x300460df 0x30045cf7 0x30044093 0x2ffaec27 0x2ffaea0b 0x34caf283 0x32852049 0x31f35 0x3adf9ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

I don´t know with what it may be related. I have attached the code where the error is thrown.

backendless-2.txt (1.96kB)

Andres,

Could you please let me know what the implementation of the following method looks like:

[ [ ApplicationDelegate dependiente] setProperties: ]

We’d like to make sure it properly uses the backendlessUser object.

Thanks,
Mark

Hi Mark.

[ ApplicationDelegate dependiente] is actually backendless.UserService.currentUser, so setProperties is the BackendlessUser setProperties method.

Andres,

It looks like you pass backendlessUser as the argument into the following method:

-(void)setProperties:(NSDictionary *)props

Since we expect NSDictionary in there, we use the allKeys method on the argument (which does not implement with the specific argument you pass).

Here’s what we’d like you to try:

[ [ ApplicationDelegate dependiente] setProperties:[user getProperties]];

Let me know if that works.

Regards,
Mark

Hi Mark.

What i am passing to setProperties is the findById method response. It was working in previous SDK versions.

It have tried what you suggest but is not working either:

‘NSInvalidArgumentException’, reason: ‘-[Users getProperties]: unrecognized selector sent to instance 0xaeae290’

I have try some different things and [user getProperties] does not return an NSDictionary. ¿Should it return one?

What i am trying to do is:

  1. Retrieve all attributtes and relationships for a specific User.
  2. Set that result to my current BackendlessUser.

After the findBy method, ¿how can i assign those results to my current BackendlessUser instance?

I have attached a screenshot when debugging in xcode. “user” object, which is the response of the findBy method, seems to be null and there is this message: “error: use of undeclared identifier ‘null’ error: 1 errors parsing expression”, which didn´t happened with previous SDK version. ¿Could this be the problem?

Regards,
Andrés

Andres,

“currentUser” is meant to be the user you’re currently logged in as. How do you obtain the initial instance? Do you use the login method?

Mark

Hi Mark.

Yes, i am using it, but login does not return all user relationships. Thats why i am using findByID method in login callback.

backendless-3.txt (3.08kB)

Hi Mark.

Could you check this problem?

I am trying to do the same thing with Android SDK (login user and run findById(user objectId) to get user relationships values because login does not return those values), and i am getting an error too, so i think i may be doing it wrong. Could you please post an example of how to do that in iOS an Android?

Regards,
Andrés

Hi Andres,

We just posted an article on the subject of relations and User accounts. You can see it at: https://backendless.com/users-and-relations-in-java-and-android/

Please review and let me know if it helps with your question.

Regards,
Mark

Hi Mark.

I have checked the post and used the same code, but I am getting this error now in login method (log messages attached):

03-27 17:48:04.679: E/AndroidRuntime(28246): BackendlessException{ code: ‘Internal client exception’, message: ‘null’ }

I can do async login, but i am getting the same error when trying to read user relationships with Backendless.Data.of( BackendlessUser.class ).loadRelations( user, rels ) …

backendless-4.txt (2.56kB)

Hi Andres,

I forgot to mention that you need to download the latest build of the SDK for Java/Android - v 1.5.

Please download the try with the latest jar.

Regards,
Mark

Hi Mark.

I got that message with the latest jar. With the old jar, i was getting a different one (user id cannot be null).

Regards,
Andrés

I just checked and login is working just fine for me. Do you run it on a device or emulator? If the latter, could you run Charles Proxy and see what the traffic on the wire looks like? Specifically what the client gets back from the server.

Regards,
Mark

I am running on a device. Is there a way to check what you say in the device?

You would need to configure a proxy on the device and point it to the Charles installation on the desktop.

Alternatively, you could create a small test as a basic Java command line project and run it on the desktop. I mean something like this:

public static void main( String[] args )
{
  // your code here to test login or whatever
}

Regards,
Mark

Hi Mark.

I have done some test with this, with iOS and Java/Android projects.

In Java project, everything is OK: i can login and fetch user relationships after that. But, in Android project (i have created a new one), i am still getting the same error: BackendlessException{ code: ‘Internal client exception’, message: ‘null’ }, which doesn´t give too many details.

I have checked that the code you posted (https://backendless.com/users-and-relations-in-java-and-android/) is for java projects because Backendless.init without context does not work in Android projects. ¿Have you tested the new SDK for Android?

In iOS, you have updated the SDK too. I have download it and tested in my project (this thread was originally open due to an iOS error). Now i can login but i am not able yet to retrieve all user relationships data. In my app, Users have 4 relationships (three are one-to-one and one is one-to-many), but i only get the one-to-many data.

I have attached two txt, one has the Android logs and the other has some iOS messages. I am very frustrated with this because i have no idea of what can be the problem here.

Backendless-iOS.txt (3.39kB)

Hi Andres,

I will check on Android and report back. Thank you for your patience.

Regards,
Mark

Hi Mark.

Could you check this problem?

Regards,
Andrés