我尝试更新系统中的所有订单,但有一个“位置”条件。我如何在 CakePHP 2.3 中做到这一点?
// OrderFood.php (Model)
$orderFood = $this->updateAll(
array(
'OrderFood.price' => 'OrderFood.original_price',
'OrderFood.discount_percent' => 0,
'OrderFood.discount_amount' => 0,
),
array(
'Order.check_num' => $check_num
)
);
// OrderFood.php (Model)
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Order' => array(
'className' => 'Order',
'foreignKey' => 'order_num',
),
'Food' => array(
'className' => 'Food',
'foreignKey' => 'food_num'
)
);
// Order.php (Model)
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'OrderDrink' => array(
'className' => 'OrderDrink',
'foreignKey' => 'order_num'
),
'OrderFood' => array(
'className' => 'OrderFood',
'foreignKey' => 'order_num'
)
);
当我尝试这样做时,Cake 返回此错误消息:
Error: SQLSTATE[42P01]: Undefined table: 7 ERRO: faltando entrada para tabela "Order" na cláusula FROM LINE 1: ...ROM "public"."order_foods" AS "OrderFood" WHERE "Order"."c... ^
SQL Query: SELECT "OrderFood"."order_num" AS "OrderFood__order_num" FROM "public"."order_foods" AS "OrderFood" WHERE "Order"."check_num" = 358171
Notice: If you want to customize this error message, create app\View\Errors\pdo_error.ctp