【问题标题】:Build a specific relation of models YII activerecord建立模型 YII activerecord 的特定关系
【发布时间】:2013-01-11 05:46:52
【问题描述】:

我正在尝试使用 CGridView 显示车辆模型。

为了显示 Fld7465RRef 引用列的值,需要以下 sql select:

select VUF._Fld7468_S as Loading_Time_To_DLR  
FROM Vehicles as Vehicles  
left join (_InfoReg7464 as VUF                 
inner join _Chrc7246 as CFU
on VUF._Fld7467RRef = CFU._IDRRef                  
and CFU._Description ='Vehicle uploading for DLRTime')                 
on Vehicles._IDRRef =  VUF._Fld7465RRef

我找不到为此查询建立关系的解决方案。

【问题讨论】:

    标签: activerecord yii models yii-relations


    【解决方案1】:

    一种方法是DAO:

    $mySqlString = "
        select VUF._Fld7468_S as Loading_Time_To_DLR  
        FROM Vehicles as Vehicles  
        left join (_InfoReg7464 as VUF                 
        inner join _Chrc7246 as CFU
        on VUF._Fld7467RRef = CFU._IDRRef                  
        and CFU._Description ='Vehicle uploading for DLRTime')                 
        on Vehicles._IDRRef =  VUF._Fld7465RRef
    ";
    $command = Yii::app()->db->createCommand($mySqlString); 
    $aResult = $command->query()->readAll();
    

    当然,你应该用这样的语句绑定你的参数,如果有的话:

    $command->bindParam(":userID", $userID, PDO::PARAM_STR);
    

    另一种方式是query-builder

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-25
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      相关资源
      最近更新 更多