cakephp:有很多不工作
device.php:cakephp:有很多不工作,cakephp,cakephp-1.3,Cakephp,Cakephp 1.3,device.php: var $hasOne = array( 'Monitordevice' => array( 'className' => 'Monitordevice', 'foreignKey' => 'deviceId', // 'deviceId' 'conditions' => '', ) ); var $
var $hasOne = array(
'Monitordevice' => array(
'className' => 'Monitordevice',
'foreignKey' => 'deviceId', // 'deviceId'
'conditions' => '',
)
);
var $hasMany = array(
'CreativeSchedule' => array(
'className' => 'CreativeSchedule',
'foreignKey' => 'deviceId',
'conditions' => '',
)
);
creative_schedules.php
var $belongsTo = array(
'Device' => array(
'className' => 'Device',
'foreignKey' => 'deviceId',
'conditions' => '',
)
);
当我称之为: $all_devices=$this->Device->CreativeSchedule->find('all') 设备表未与创造性的\u计划进行任何连接 相反,我得到了两个查询:
SELECT `Device`.`id`, ....FROM `devices` AS `Device` LEFT JOIN `monitordevices` AS `Monitordevice` ON (`Monitordevice`.`deviceId` = `Device`.`id`)
及
使用
在这两个类中,添加:
var $actsAs = array( 'Containable' );
那么您的发现应该如下所示:
$all_devices = $this->Device->CreativeSchedule->find('all', 'contain' => array('Device'));
作为一个旁注,我不确定你把FoD()放在哪里,如果那个控制器使用CreativeSchedule,但是只考虑$----CopyStudioChorde>查找(…),如果你可以,因为模型链接会导致性能降低,并且它不会通过它们的关联将查询链接在一起。(我不确定你是不是在假设。)
在更糟糕的情况下,如果愿意,您可以将$this->loadModel('CreativeSchedule')放在控制器操作的顶部。使用 在这两个类中,添加:var $actsAs = array( 'Containable' );
那么您的发现应该如下所示:
$all_devices = $this->Device->CreativeSchedule->find('all', 'contain' => array('Device'));
作为一个旁注,我不确定你把FoD()放在哪里,如果那个控制器使用CreativeSchedule,但是只考虑$----CopyStudioChorde>查找(…),如果你可以,因为模型链接会导致性能降低,并且它不会通过它们的关联将查询链接在一起。(我不确定你是不是在假设。)
在更糟糕的情况下,如果愿意,您可以始终将$this->loadModel('CreativeSchedule')放在控制器操作的顶部。您是否在代码中的其他地方设置了选项
recursive
?设置recursive=>-1
告诉CakePHP不要加入相关模型。否,但我的问题已经解决,为设备模型定义了主键字段。您是否在代码中的其他地方设置了选项recursive
?设置recursive=>-1
告诉CakePHP不要加入相关模型。否,但我的问题已解决,为设备模型定义了主键字段。