Hi, i have a question regarding the best practice with the user relations table and other tables I have created. I have created an event making app for android where users can create events. Currently I have a users table with email, password and a persons property which is a 1:1 relationship to person table, my person table has additional user information such as name, country, phone etc, it also has properties such as MyCreatedEvents, GoingToEvents etc which are 1:many to my events table, in my app a ‘person’ can add another ‘person’ as contact and then from this list of contacts invite them to events. However my question is should I bring my person table into my user table and then the MyCreatedEvents and InvitedEvent properties in my user table could have 1:many relationship to the event table.
My concern with this however bringing my person table into my user table is that I would be dropping my person class which i feel gives me easy access to my properties using the class I have that maps to the table particularly my MyCreatedEvent properties etc that are 1 : many with Events table. Would there be an issues with this or is it recommended to keep this separated in user and person table. I feel that it would be better practice to bring in my person table into my user table as I could then use the update api with the users table and since I also want to use the easy facebook login which maps to the user table.
Currently my app works fine but since I want to expand it further I think this is what I should do, I would just like some advise before I begin the change on the backend and the app itself! Thanks!
Hi, Leonard,
In my opinion if entities have one-to-one relations they should be kept in one table. However if your additional data tend to be dynamic, for instance you may add some columns, I think it`s better to create separate table for it.
Btw, Users table supports multiple one-to-one or one-to-many relations.
Regards,
Artur.
Thanks for clarifying that. Just in regards to logging in and registering users with the Facebook SDK (specifically the Backendless SDK), can Facebook properties such as name and country etc be mapped to tables other then my users table (as far as I’m aware it returns a user entity populated from the mapped Facebook credentials) in which case this would only work if I brought my person table data into my System table - users? Thanks!
Hi, Leonard,
You can not map custom user properties to another table.
However you can create an event handler on register event so that you can map any property to any table.
Regards,
Artur.
Hi, I have been working on the solution you have provided however I am not having to much luck. I have created a new event handler, event: register for the users table and the call timing is after, however the Facebook login is not triggering the event handler created when I sign in a user with the easy Facebook login, it is creating a new user in the users table as I would expect, but the after register event handler is not being called. I assume this was what you meant in your previous post as a solution, however it doesn’t seem to be working. Am I doing something wrong or should I be using another event handler? Thanks Leonard.
Can you clarify what the ultimate goal here is? Do you need to make a copy of the Facebook user properties such as “name” and “country” in one of your tables?
Hi Mark,
I want to be able to register a user which maps to a person entity that in is the persons table My users table only has email (identity) and password, users table maps 1:1 to the persons table which has name, country and phone and some other properties etc. The way I have structure my app and data is I don’t think its possible or an easy fix to simply pull all these properties into my users table. So I’m currently trying to map certain Facebook properties to my users table and the rest to my persons table when users register/login using the easy facebookSdk.
Cheers.
Leonard
Hi Leonard,
With the code you already have now, do get the values for the Facebook properties you need to map? Getting those properties is the first step, saving them in Backendless is what you do after.
Mark
Hi Mark, I am currently getting all the Facebook properties needed to map with the afterRegister() in the hashMap result.
Cheers.
Leonard.
Hi Leonard,
Unless I am missing something, if you already get the values for these properties, it should be very straight-forward to save them either in the “Person” or the “Users” tables.
Regards,
Mark
My apologies, I got things mixed up from when I i used the Backendless.UserService.register() which returned me a result with all the fields submitted in the register. So currently I do not get the values for the Facebook properties needed to map which was step 1 you mentioned… Apologies for the confusion! The custom event handler AfterRegister does not get triggered when a user logs in and register with the easy Facebook for the first time.
Leonard
Let’s ignore the custom event handler for the moment. Can you get the needed property values on the client side after the callback from the server is made?
Mark
Hi Mark, Ive tested for required properties and I am able to get the values on the client side after the callback from the server is made in the handleResponse of the loginWithFacebook.
Once you have values on the client, simply make an API call to save them in a Backendless table.
Hey Mark this is working now which is good, I’m updating the person each time they log in from the facebook properties in both user table and person which I suppose this is probably better then not, was getting some duplicate properties errors when updating but am just removing those properties and it works well. Appreciate the help. Cheers.
I am glad you got it working!