简体   繁体   中英

One-to-one and one-to-many relationship in the same table is possible?

I have Texts and Users tables. The user can be a corrector or writer. Each text has only one corrector and one writer. But each user can write many texts and a corrector can correct many texts. What is the correct way to model the relationship of these 2 tables?

Does the Text table need to have user_id and corrector_id fields? Or just make a many-to-many relationship?

If you need to have user_id and corrector_id fields, how would these 2 fields relate to the user table? And if it is correct to use many-to-many what would be the correct way to get the data of the writer and the corrector of a text?

Thank you!

you can build a bridge table with a field that descrite the type of relationship(author corrector) as you have her an:m relatiopnship between text and users

you need also zto make the columns of the user_text table unique so that you conditon that only 1 corrector and 1 writer is complied

users        user_text         text
user_id      user_id           text_id
             text_id
             type

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM