Here’s the situation –

I am exposing an external database (and it’s tables) to drupal views using hook_views_data. When I describe these tables with their fields and the joins between tables , they show up in the views UI and everything is good.

The problem I have now come into is –

Table A has two columns ID1 and ID2 Table B has primary key ID and other Columns – Fruits , Meats , Veggies.

I want to join Table A with Table B on Table A.ID1 = Table B.ID and get the Fruits column. Table A with Table B on Table A.ID2 = Table B.ID and get the meats column.

So basically, I want to specify join relationships between two tables on multiple columns and I am not able to find a way to do that.

I tried just writing the two joins like this –

$data['TableB']['table']['join']['TableA'] = array(
'left_field' => 'ID1',
'field' => 'ID',
);

$data['TableB']['table']['join']['TableA'] = array(
'left_field' => 'ID2',
'field' => 'ID',
);
But it joins only allows joins on one column and ignores the other column.

In a normal SQL query , it would work by giving a table an alias in the select and join parts of the query like -

Select A1.Fruits , A2.Meats
From Table A
Left join Table B on Table A A1.ID1 = Table B.ID
Left join Table B on Table A A2.ID2 = Table B.ID
I've been trying to find a way to implement this in drupal views but am stuck without a solution. I'd really appreciate any help i could get!

Thanks!