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

screwtape_mk's avatar

Multiple tables on a model / relationships, whatever is allowed

I have a Bookings model

Bookings.php

with

protected $table  = 'V_BOOKINGS'

'V_BOOKINGS' is a mysql view that contains user’s booking data with other info from other tables in it.

I have another table that also contains user bookings :

user_bookings 

it is part of the view above but not with enriched data as the V_BOOKINGS view

I have a BookingsController that is supposed to add data into user_bookings, except it only attempts to insert into the view above, which is fine - I wasn’t expecting it to.

What I want to do is to insert the data in the controller to : user_bookings. Except I have now learned my model can only have 1 table.

I apparently have to create a relationship between the view and the table. Well theres no real logical relationship except to say theres one-to-one relationship between the 2 ‘booking’ models..

If i'm on the right track on creating these relationships , do let me know and if you won’t mind show by way of a code snippet how this would be done

0 likes
3 replies
bobbybouwmann's avatar
Level 88

I'm not really sure why you need a relationship here. Two models would fix your problem right? One model for retrieving the data and one model for storing the data. Or am I missing some context?

1 like
Snapey's avatar

I agree

create a Vbookings model for accessing the view

1 like
screwtape_mk's avatar

Thought there was another way but yeah relationships not necessary THANKS

Please or to participate in this conversation.