Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Elsieza's avatar

One Foreign key with multiple reference table

I have 4 table with one table has relation 3 tables. Lecturer (id, name, contact, email) Registrant (id, name, contact, email) Assistant (id, name, contact, email)

and Phonebook (id, name, contact, email)

id in phonebook table has a relation of 3 tables id lecturer, registrar and assistant. and 1 id owned only one name. how do I make the relations in the model and call the function in the controller.

thanks for the answers given, pardon my language less understandable

0 likes
4 replies
Snapey's avatar

Each record in the three tables should link to the phone record. This will need a phone_id column on each table.

If you don't ever need to find the owner from a phone record then you can forget that relationship

Then, in each of the models for Lecturer, Registrant and Assistant create a hasOne relationship to the phones.

Otherwise, look into Polymorphic relationships

shez1983's avatar

or lecturer/registrant & assistant are basically the same thing so have one table?

Elsieza's avatar

Thanks for helping, but I still do not understand ... because the existing data in the table assistant, lecturer, and applicants wanted me to copy the phonebook table. because I wanted to create a phonebook data based on input data. thanks for help

Please or to participate in this conversation.