What I have
In my OrdersTable.php
:
$this->belongsTo('OrderStatuses', [
'foreignKey' => ['order_status_id', 'language_id'],
'joinType' => 'INNER',
'className' => 'OrderStatuses',
]);
The above association generates the following join statement:
FROM
order
Orders
INNER JOINorder_status
OrderStatuses
ON (
OrderStatuses
.order_status_id
= (Orders
.order_status_id
)
ANDOrderStatuses
.language_id
= (Orders
.language_id
) )
What I want
I want to join on a specific language_id
(that is, provide an integer) instead of what’s in the respecive Orders
.language_id
. An important detail is I need to do this dynamically, based on whatever language_id
I have in the environment at any given moment. So while my below configuration attempts happened in the table class itself just to see if what I’m after is at all possible, I will need this to happen in an outside class that calls $table->associations()
and modifies them on the fly.
What I tried
-
$this->belongsTo('OrderStatuses', [ 'foreignKey' => ['order_status_id', 'language_id'], 'conditions' => [ 'OrderStatuses.language_id' => 5, ], 'joinType' => 'INNER', 'className' => 'OrderStatuses', ]);
This results in Record not found in table “order”:
INNER JOIN
order_status
OrderStatuses
ON (
OrderStatuses
.language_id
= 5
AND (
OrderStatuses
.order_status_id
= (Orders
.order_status_id
)
ANDOrderStatuses
.language_id
= (Orders
.language_id
)
) ) -
$this->belongsTo('OrderStatuses', [ 'foreignKey' => ['order_status_id', 'language_id'=>5], 'joinType' => 'INNER', 'className' => 'CakePHPOpencart.OrderStatuses', ]);
This results in Database Error:
INNER JOIN
order_status
OrderStatuses
ON (
OrderStatuses
.order_status_id
= (Orders
.order_status_id
)
ANDOrderStatuses
.“ = (Orders
.5
) )