Database relationships don't work right

Hello.
I have some troubles on database relationships.

Let me explain shortly:
I have created two tables as Users and Phones.
Phones model has several columns such as phone_type, phone_name, phone_number and etc.
A user can have several phones.
So I think the relationship between Users and Phones is 1:N and then I have set the relation line according to my idea.
But it doesn’t work right now.

If I changed the phones model data, it reflects in all users.
Could you provide me some good advice?
Then hope to let me know how to make these two models and set the relationship?

Thanks in advance.

Hello @Alex1

Could you provide an example of your Set/Add Relation operation?

Regards, Dima.

Hello, Dima.
Thanks for your reply.

For example, I have created two models (Roles and Permissions.)
Each role has all permissions in the permission model.

This is my Roles Table model schema.

And This is my Main Permission Schema.

This is my Sub Permission Schema.

I have set the relationship such as below screen.

As I mentioned, Role:Main Permission is 1:N, and Main Permission:Sub Permission is also 1:N.
And each role has all main permission s and also each main permission has all sub permissions.

The trouble is when I change the main permission data, it reflects in all roles in role table.
In this case, sub permissions are also same as above.

I think I have some fault in the relationship between model schemas.
How can I fix it?

Please explain more detail.
Looking forward to hearing from you soon.

Thanks

What data do you change? And what did you expect?
Because the things that you say sound pretty right.

When you change relation data, objects that rely on it will get updated information. That’s how relations work.

Hi.
Then what I want is that each role has different main permissions.
I am sure my relationship is not right.
But I don’t know how to do it what I want.
I mean, each role has different main permissions and when I change the one role’s main permission data, it is not needed to reflect to another role.

Hope to hear from you best solution.
Thanks again.

That sounds not right

I mean, each role has different main permissions and when I change the one role’s main permission data, it is not needed to reflect to another role.

In that case, you should reorganize your table in a way, where Main Permission - it’s just a flag record, without any data. You could move that data to the Roles Table, or maybe another table and Roles table will rely on it.

OR

You could duplicate every permission that requires different data.

But I prefer the first approach.

Thanks.

Could you please give me a sample example?
I am not sure what I have to do.

Thank you.

Could you tell me a case when role A and role B have main permission C. But permission C have different data for roles A and B?

Role A has all colums of role B and role B also has all colums of role C.

So Role C is related role B and role B is related to role A.
You can refer the screenshors in my previous message .

Thanks.

But they are in the same table. They can’t rely on each other.

Referring to your screenshots I guess that you need to reorganize the schema. But I still can’t catch which data is different between the permissions with the same type.

Let me explain my problem as clear as possible.

Let’s assume that role table has two object “X, Y” and the main_permission table has three object “A, B, C”.
Sub_permission table has also three object “1, 2, 3”.

The objects of role table has all objects of main_permissions table.
( I mean “X” has “A, B, C” and also “Y” has “A, B, C” )
The main and sub_permission table has also same relationship.

What I want is that if I change the permission table’s value to “B, C, D”, then it is only reflected to role X, not Y.

If you think I created the table schema wrong, please let me know the sample schema to implement my idea.
It’s a little urgent so I am asking for your help.

Thanks in advance.

Hi Alex.
I think my friend Zoran explained detailly what I am going with trouble.

Please send me the best solution to fix it.
Best Regards.

What I want is that if I change the permission table’s value to “B, C, D”, then it is only reflected to role X, not Y.

has also same relationship and only reflected to role X - points that couldn’t exist at the same time.

You describe entity Permission, but it doesn’t look like permission at all, because you change it and they are not common(the reason of it - you don’t want “reflection”).

There are a lot of ways to solve your problem like:

  • doesn’t use relations but uses some string keys and additional find by this key
  • or make a bunch of “permissions” for every role that will look the same, but exist independently.
  • or make a correct schema where permission is real permission, consistent, and common for everybody.

All those things could or couldn’t fit your business logic, and I can’t say which one you should use.

As for:

It’s a little urgent so I am asking for your help.

and

Please send me the best solution to fix it.

Please, take into account that this forum was created to help our user with their issues related to Backendless. In your case, it’s not a bug or even a Backendless-related issue.
If you want to get help with your business logic, you could contact sales@backendless.com

Regards. Dima.

Hi. Alex.
Thanks for your message.

I will try to do it following your method.
And I will consider your opinion.
Please don’t misunderstand me.

Thanks.