在我的模型“ mesn”中,我属于关系:

    public $belongsTo = array(
        'Order' => array(
            'className' => 'Order', 'foreignKey' => 'order_id', 'conditions' => '', 'fields' => '', 'order' => ''
        ), 'SaleOrder' => array(
            'className' => 'SaleOrder', 'foreignKey' => 'sale_order_id', 'conditions' => '', 'fields' => '',
            'order' => ''
        ), 'ShippedBox' => array(
            'className' => 'Box', 'foreignKey' => 'shipped_box_id', 'conditions' => '', 'fields' => '',
            'order' => ''
        )
    ); /*     * * hasMany associations** @var array


在我的一个模型函数中,我想在“属于”“ ShippedBox”(表:box)上连接另一个表。但是不管我如何尝试编写联接,都会收到未知列的错误消息:

$arr_s_result = $this->find('all', array(
  'joins' => array(
    array('table' => 'shipments',
      'alias' => 'MyShipments',
      'type' => 'INNER',
      'conditions' => array(
      'MyShipments.id = ShippedBox.shipment_id'
    )
  )),
  'conditions' => array('Mesn.name' => $arr_search), 'recursive' => 0
));


我试过了:

'MyShipments.id = ShippedBox.shipment_id'




'MyShipments.id = box.shipment_id'


乃至

'MyShipments.id = Boxes.shipment_id'


存在带有字段“ shipment_id”的表“ boxes”的位置。

我怎样才能使这个加入工作?

最佳答案

'MyShipments.id = box.shipment_id'


至:

'MyShipments.id = Box.shipment_id'


还有什么呢:

$arr_s_result = $this->find('all', array(
                              'conditions' => array('Mesn.name' => $arr_search), 'recursive' => 0


));

EmiratesTo连接是自动完成的。

关于mysql - CakePHP 2.x:加入属于,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21634332/

10-11 21:56