# How should this one-to-one link be modelled?

**URL:** https://discourse.processing.org/t/how-should-this-one-to-one-link-be-modelled/38802
**Category:** Project Guidance
**Created:** [September 16, 2022, 12:55pm UTC](https://discourse.processing.org/t/how-should-this-one-to-one-link-be-modelled/38802 "2022-09-16T12:55:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![neon124](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neon124/32/16509_2.png) [@neon124](https://discourse.processing.org/u/neon124)
#### Post date: [September 16, 2022, 12:55pm UTC](https://discourse.processing.org/t/how-should-this-one-to-one-link-be-modelled/38802/1 "2022-09-16T12:55:39Z")

</div>

I have a number of entities that represent the various user kinds that must be able to access a certain system. They also come with a variety of information attached to them.  
​ ​

For instance, “admin user” has a workstation number and “ordinary user” has an email address (note that this is a hypothetical case). Additionally, both parties share similar attributes including first and last names, addresses, and phone numbers. Last but not least, they obviously need a (unique) username and password to get in.  
​ ​ ​

The user only has to enter his user name and password in the program, and depending on the user type, the functionality of the application varies somewhat. You can assume that the username for this task has to be distinctive.

How can I effectively simulate this?

I can’t just make two tables since then I can’t make sure the user name is unique.

Additionally, I am unable to include them all in a single table due to the many types of unique data that are related to each.  
​ ​ ​

I believe I might need three different tables: one for “users” (with user name and password), one for “regular users,” and another for “admin users.” But how would the relationships between these three databases function? Or is there another approach?

​( By the way, since MySQL is the target DBMS, I doubt the database system itself supports [generalization](https://www.scaler.com/topics/generalization-in-dbms/).)

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [September 16, 2022, 1:09pm UTC](https://discourse.processing.org/t/how-should-this-one-to-one-link-be-modelled/38802/2 "2022-09-16T13:09:22Z")

</div>

Hi @neon124,

I might expect this to be posted on another forum which is not Processing related but rather SQL / database modelling focused 😉

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [September 16, 2022, 1:32pm UTC](https://discourse.processing.org/t/how-should-this-one-to-one-link-be-modelled/38802/3 "2022-09-16T13:32:40Z")

</div>

Hi @neon124,

agree with that:

> [@josephh](#):
>
> I might expect this to be posted on another forum which is not Processing related but rather SQL / database modelling focused

but also don’t understand you problems…

You have users for the system, which needs a loginname and a password (other attributes like real names etc doesn’t matter on this stage).  
loginname can be whatever it is (AP name, email, etc),  
password with some security standards

With this information you look if the user credentials are correct on login.

The other things you are talking about are roles. So the users in you system need a role applied (ie Admin, regular user, or other special roles)

As the user successfully logged in you can decide on the role what he/she it able to do on the application !?

Simplified

> Table User  
> unique id, username, encpassword,Role [ref roleid], …  
> 1,user1,xxxxxxxx,1, firstname, lastname, etc  
> 2,user2@domain.xxxxxxxx,2, firstname, lastname, etc

> Table Role  
> unique roleid, rolename, permissions  
> 1, Admin, [READ,WRITE,DELETE]  
> 2, Manager, [READ,WRITE]  
> 3, Regular, [READ]

No magic… 🤷‍♂️

Cheers  
— mnse
