在yii2中获取sqlDataProvider中的相关模型

时间:2016-08-23 08:38:29

标签: php yii2

执行查询,我想在yii2中的sqldataProvider中获取相关记录

这就是我试过的

      $sql ="
        SELECT
    tblpritems.PRlineID
    , tblpritems.Tracking_Code
    , tblpritems.Description
    , tblpritems.Quantity
    , tblpritems.Unit_Price
    , tblpritems.Extended_price
    , tblpritems.PRID
    , tblpritems.pr_solicitation_id
    , tblpritems.date_item_received
    , tblpritems.Quantity_received
    , tblpritems.Remarks_on_receipt
    , tblpritems.Received_by

FROM
    prts.tblpritems
    INNER JOIN prts.tblpr 
        ON (tblpritems.PRID = tblpr.PRID)
    INNER JOIN prts.tblprsolicitations 
        ON (tblprsolicitations.PRID = tblpr.PRID) AND (tblpritems.pr_solicitation_id = tblprsolicitations.pr_solicitation_id)
    INNER JOIN prts.tblprsuppliers 
        ON (tblprsuppliers.pr_solicitation_id = tblprsolicitations.pr_solicitation_id)
    INNER JOIN prts.tblpo 
        ON (tblpo.pr_supplier_id = tblprsuppliers.pr_supplier_id)
  where tblpr.PRID=".$val." and tblpo.PO_Status_ID=7 and item_received_status=0
    ";

    $connection = Yii::$app->getDb();
    $command = $connection->createCommand($sql);
    $result = $command->queryAll();

    $dataProvider = new SqlDataProvider([
        'sql' => $sql,
        'pagination' => [
            'pageSize' => 10,
        ],
    ]);

当我表演时

的var_dump($ dataProvider-> getModels()); 它会返回所有记录,但是当我尝试

  $data = $dataProvider->getModels();
    foreach ($data as $dat) {
        $data = $dat->getRelatedRecords();
        var_dump($data);
    }

这总是向数组

上的成员函数getRelatedRecords()返回Call的错误

如何访问相关记录

0 个答案:

没有答案