Relation Users table and DeviceRegistration

Hello.
How I can set the relation between Users table and DeviceRegistration table.
I want to allocate DeviceRegistration row to the user row

Please check this documentation: https://backendless.com/docs/android/data_relations_set_add_overview_android.html

Regards,
Olha

@saeed_noshadi

Hey! Olha’s solution will work, but in fact all you need to do to establish a relation between a device and a specific users who owns it (the device) - you need to call registerDevice API while user is logged in.

So:

  1. Log in a user
  2. Call registerDevice API
  3. Check Data > DeviceRegistration table to verify that User object and DeviceRegistration object are now linked.

Please read this doc for more details - https://backendless.com/docs/android/push_managing_registrations.html

Anton

Please more helping with this comment.
I wanna after registering users in the Users table, Also record the user’s phone and identify with a relationship

@saeed_noshadi

There is the “DeviceRegistration” field in Users table already. So after calling registerDevice method by authorized user, you can check Users table using console and see, that the relation between this user and DeviceRegistation was added.

01%20PM

I used “Backendless.UserService.register” for a register user account and after that into another activity, I used “Backendless.Messaging.registerDevice” this code for the register user device but DeviceRegistration filed is null for this user.

this is complete code:

    Backendless.UserService.register(user, object : AsyncCallback<BackendlessUser> {
        override fun handleFault(fault: BackendlessFault?) {
           
        }

        override fun handleResponse(response: BackendlessUser?) {
            
        }

    })

and Register device complete code:

  val channels = ArrayList<String>()
    channels.add("default")
    Backendless.Messaging.registerDevice(channels, object : AsyncCallback<DeviceRegistrationResult> {
        override fun handleResponse(response: DeviceRegistrationResult) {
        }

        override fun handleFault(fault: BackendlessFault) {
           
        }
    })

Register new user and login by user are not the same things. If you check Backendless.UserService.CurrentUser() after registering new user, you’ll see null.

User have to login into app after registering. And then device registering will work as you expect.

Did you create this column?
how create this column?

As mentioned earlier Andrii,

  1. you do no need to create relation column by yourself.
  2. Register new user and login by user are not the same things. User should be logged in before device registration.