0

我正在尝试这样做:

$this->PickTicketLineModel->PickTicket->SO->CustomerShipToModel

如果我浏览每一部分,我会得到一个 PickTicketLine 模型,一个 PickTicket 模型,一个 SO 模型。当我到达 CustomerShipToModel 时,我返回 null。由于这应该与数据库中的现有行匹配,我假设关系出了问题。有什么建议么?

Pick Ticket Line Table 关系

'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));
4

1 回答 1

3

尝试显式地急切加载所有相关数据:

$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
    )
)
于 2012-08-14T20:05:11.453 回答