我正在尝试这样做:
$this->PickTicketLineModel->PickTicket->SO->CustomerShipToModel
如果我浏览每一件作品,我会得到一个PickTicketLine模型,一个用于PickTicket,一个用于SO。当我到达CustomerShipToModel时,我得到了null。因为这应该与数据库中的现有行匹配,所以我假设关系出现了问题。有什么建议吗?
选择故障单线表关系
'PickTicket' => array(self::BELONGS_TO, 'TblwhPickTicket', 'PickTicketNumber'),
选择故障单表关系
'SO' => array(self::BELONGS_TO, 'TblsoSO', 'SONumber'),
SO表关系
'CustomerShipToModel' => array(self::BELONGS_TO, 'TblarCustomerShipTo', 'CustomerShipTo'),
客户发货到表关系
'CustomerShipToModel' => array(self::HAS_MANY, 'TblarsoSO', 'CustomerShipTo'),
这就是我首先获得PickTicketLine模型的方式:
$this->pickTicketLine = TblwhPickTicketLine::model()->with('PickTicket','PickTicket.SO')->FindByPk(array('PickTicketNumber'=>$pickTicketNumber, 'PickTicketLineNumber'=>$pickTicketLineNumber));
答案 0 :(得分:4)
尝试明确加载所有相关数据:
$this->pickTicketLine = TblwhPickTicketLine::model()->with(array(
'PickTicket' => array(
'with' => array(
'SO' => array(
'with' => array('CustomerShipToModel')
)
)
)
))->findByPk(array(
'PickTicketNumber'=>$pickTicketNumber,
'PickTicketLineNumber'=>$pickTicketLineNumber
));
如果这不起作用,请按照Pentium10在评论中的建议记录您的数据库请求并检查查询。你可以让phpMyAdmin执行查询或使用MySQL“EXPLAIN”关键字获取更多信息。要获取相关日志,您必须将以下行添加到config / main.php文件中:
'components'=>array(
'db'=>array(
'enableProfiling' => true,
'enableParamLogging' => true
)
)