我可能错过了一些在这里痛苦明显的东西。我试图在Cake中连接多个表,但我只从第一个表获取字段。请看下面的代码..CakePHP模型连接问题,缺少连接表中的字段。
$joins = array();
$joins[] = array(
'table' => 'products',
'alias' => 'Product',
'type' => 'LEFT',
'conditions' => array(
'Device.id = Product.device_id'
)
);
$joins[] = array(
'table' => 'pricepoints',
'alias' => 'Pricepoints',
'type' => 'LEFT',
'conditions' => array(
'Pricepoints.product_id = Product.id'
)
);
$all_products = $this->Device->find('all', array("joins" => $joins);
这返回下面的SQL
SELECT `Device`.`id`, `Device`.`manufacturer_id`, `Device`.`name`, `Device`.`type_id`, `Manufacturer`.`id`, `Manufacturer`.`name` FROM `devices` AS `Device` LEFT JOIN products AS `Product` ON (`Device`.`id` = `Product`.`device_id`) LEFT JOIN pricepoints AS `Pricepoints` ON (`Pricepoints`.`product_id` = `Product`.`id`) LEFT JOIN `manufacturers` AS `Manufacturer` ON (`Device`.`manufacturer_id` = `Manufacturer`.`id`)
即。它只返回父模型的字段,即。设备。我如何才能从连接中选择所有字段?我假设它与我建立模型关系的方式有关,但我认为我已经正确设置了这些关系。
任何人的任何建议?
由于@pleasedontbelong说您需要指定字段,因为您没有将它直接关联到设备模型。如果您使用许多或belongsTo或HABTM的关联,则可以使用递归选项来显示与其获取的模型相关的数据 – api55
,但在cakephp网站中没有说明,它们的错误文档 – neobie