Laravel Relationship: a table having ids from two other tables
Hello!
I have two tables: 'tours' and 'tourists' in my DB.
A 'tour' can have MANY 'tourist's, and 'tourist' can participate in MANY 'tour's. So, I have successfully related them via 'begonsToMany" relationship (when adding rows to "tours' and 'tourists" an intermediate table 'tour_tourist' is given a row also.
"tour_tourist" table structure is:
tour_id | tourist_id 1 | 37 1 | 38 1 | 39 (tourists with id's 37, 38 and 39 go are assinged to the tour with id = 1)
THE PROBLEM : One of 'tourists' (37 or 38 or 39 from example abouve) can be a 'buyer' of the 'tour' (1 from above table). So only 1 person pays for the tour. Also this person can go to the tour/only pay for it. I pass this data (tour, tourists, who is buyer and does he goes to the tour) when submitting a tour via web-form.
So I want to create a 3rd table, called 'buyers' which represent a "tourist" who pays for the tour:
tour_id | tourist_id | is_tourist 1 | 39 | 0 (1. one 'tour_id' can match only ONE 'tourist_id')
(2. 'tourist_id' should be one of those who 'belong' to the 'tour_id' in the previous "tour_tourist" table - tourist 39 belongs to tour 1 - see table above).
(3. 'is_tourist' is 1/0, means the buyer goes to the tour/only pays, in my example it's 0 - he only pays, doesn't go).
I am wondering how can I do this using Eloquent relationships (one-to-one? hasManyThrough?) .
Appreciate any help.
Please or to participate in this conversation.