lundi 10 décembre 2018

Laravel many-to-many relationship with multiple custom pivot tables?

I hope I'm not asking an already answered question, but using all the search terms I can think of I can't work out a solution to this:

I have two tables, companies and respondents

Sometimes, a respondent can select one or more companies. A company can be selected by one or more respondents.

Other times, a respondent can rate one or more companies. A company can be rated by one or more respondent.

It is possible for a respondent to both select and rate a company. (Indeed, all companies that a respondent rates they have to have selected, but they don't rate all the companies they select).

As a further complication, a respondent is an employee of one company only, and is also nominated by one or more companies to to the selecting and rating.

My line of thinking is to have multiple custom pivots:

//relationship between 'companies' and 'respondents' to show who they selected 
selected_companies 

//relationship between 'companies' and 'respondents' to show who they rated 
rated_companies 

//relationship between 'companies' and 'respondents' to show which companies a respondent was nominated by 
nominating_companies

//relationship between 'companies' and 'respondents' to show who a respondent is employed by
employment

I guess the last one is a simple one to many, so I can just put a custom named FK of employer_id in the respondents table.

Other than that, I'm pretty stuck as to how to implement this. I know that custom intermediate pivot models is a thing, but I also can't figure out how to implement that.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire