mysql - polymorphic association alternative -


i'm trying design part of database should cover users login. users can login "local", "facebook" or "google" account.

what have table users contains 2 columns, login_type login_id. values of login_type can "local", "facebook" or "google" refers 3 tables: local, facebook , google. login_id id of login_type referenced table.

i don't polymorphic association , redesign part keep database simple , coherent creating tables references usual foreign key.

appreciate suggestion

regards

what doing trick known in object relational mapping (orm) systems discriminator column. problem it, understand, referential integrity goes out window, because cannot declare login_id being foreign key maps table, because may map 1 of 3 possible tables, , table maps chosen value of login_type column.

the way correctly might seem bit strange, guarantee referential integrity.

table users columns:      id                    primary key      local_users_id        foreign key, references local_users(id)      facebook_users_id     foreign key, references facebook_users(id)      google_users_id       foreign key, references google_users(id) 

so, login_type column abandoned, , instead introduce 3 nullable foreign keys: local_users_id, facebook_users_id, , google_users_id. 1 of them may non-null.

you can make sure 1 of them non-null in code, or in database, trigger.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -