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

gpalmer711's avatar

Returning Data from two tables in relationship

HI All, I'm pretty sure I'm missing something obvious and would appreciate it if someone could point me in the right direction. To simplify, I have 3 tables and 3 associated models.

Company
ID
Name
Settings
ID
Name
SettingToCompany
ID
company_id
setting_id
value

There will only be one instance of each setting per company. So assuming an entry in the company table with an ID of 1 and name of 'Dummy Company' and two entries in the settings table with the IDs of 1 and 2 with names of 'Setting1' and 'Setting2' - My SettingToCompany table would look like this:

|ID | company_id | setting_id | value|
|1 | 1 | 1 | hello|
|1 | 1 | 2 | word|

I have a function in my company model, that gets the settingToCompany values, based on my current company. I would like to also return the name associated with the setting within the same function?

0 likes
2 replies
gpalmer711's avatar

Thanks @furqandev - That pointed me in exactly the right direction and I now have things working as needed.

Appreciate the swift response.

1 like

Please or to participate in this conversation.