We have a table that has 3 independent keys which point to a single second table; each of these keys is independent and represents a separate relationship. An example might be a single order which can relate to multiple salespeople.
Something like this:
Table 1
- Table 1 PK
- FK1 => Table 2 PK
- FK2 => Table 2 PK
- FK3 => Table 2 PK
- Column A
- Column B
Table 2
- Table 2 PK
- Column C
- Column D
I would expect to be able to connect the two tables, automatically adding multiple duplicate columns from the second table in my result set (perhaps with a prefix or suffix derived from the foreign key). So we might see something like this:
Joined table (expected)
- Table 1 PK
- Column A
- Column B
- FK1 Table 2 PK
- FK1 Table 2 Column C
- FK1 Table 2 Column D
- FK2 Table 2 PK
- FK2 Table 2 Column C
- FK2 Table 2 Column D
- FK3 Table 2 PK
- FK3 Table 2 Column C
- FK3 Table 2 Column D
When I try to include both tables in the query builder, the second table only appears once in the resulting columns. Additionally, no matter how I set up the relationships, the query builder attempts to group all 3 relationships together (join on FK1 = T2 PK AND FK2 = T2 PK AND FK3 = T2 PK). This is not reflective of the data model. We also only see one set of table 2's columns in the result, something like this:
Joined table (actual)
- Table 1 PK
- Column A
- Column B
- Table 2 PK
- Table 2 Column C
- Table 2 Column D
Is there any way to do what I'm trying to do using the query builder? Or will I need to write manual SQL for this? Thanks!