订单对象的YII2模型

时间:2019-04-05 14:51:56

标签: php model yii2 erp

我正在尝试在YII2中创建一个高性能模型。我已连接2个数据库(MSSQSL:自己的数据库和ERP系统)-它可以工作。现在,我尝试从ERP系统加载订单。系统将所有订单信息分布在不同的表中。

表格:订单

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim lngResultsCount As Integer
    Dim dicComboBoxValues As New Scripting.Dictionary
    dicComboBoxValues.Add(3, "0")
    dicComboBoxValues.Add(2, "1")
    lngResultsCount = dicComboBoxValues.Count
    Dim aenmKeys() As Object
    aenmKeys = CType(dicComboBoxValues.Keys, Object())
    Dim lngComboLoopIndx As Integer
    Dim udtComboData As New udtComboBoxData
    For lngComboLoopIndx = 0 To lngResultsCount - 1
       'the below line is throwing the error
        udtComboData = CType(dicComboBoxValues.Item(aenmKeys(lngComboLoopIndx)), udtComboBoxData)
    Next
End Sub

Public Structure udtComboBoxData
    Dim ComboBoxItems() As String
    Dim DefaultIndex As Integer

End Structure

End Class

表:订单信息1

CREATE TABLE [dbo].[Order](
    [ID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [orderid] [int] NULL,
    [name] [varchar](10) NULL,
    [type] [tinyint] NOT NULL,
    [lastupdate] [smalldatetime] NOT NULL,
....

表:订单信息2

CREATE TABLE [dbo].[Order_Information1](
    [ID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [Parameter] [int] NULL,
    [Value] [varchar](255) NULL,
....

我已经为所有模型创建了,并且还可以单独访问表格。在订单模型中,我建立了一个类GetInformationData:

CREATE TABLE [dbo].[Order_Information2](
    [ID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [Parameter] [int] NULL,
    [Value] [varchar](255) NULL,
....

它可以工作,但是非常慢。每个订单约有500个参数 直到所有内容加载完毕,才需要半个永恒;-(

我试图连接模型,但不幸的是没有成功。

public function getInformationData ()
{

    $description = Order_Information2::find()->select('Value')->where(['ID' => $this->id, 'Parameter' => 'txt_ description'])->one();
    //...
    $this->description =  !empty($description) ? $description->Value : '';
    //...
}
    //...

1 个答案:

答案 0 :(得分:0)

您没有共享太多细节,但是您可以在一个查询中查询所有参数,并避免创建模型(由于只需要Value,因此似乎没有使用):

public function getInformationData () {
    $data = Order_Information2::find()
        ->select(['Parameter', 'Value'])
        ->where(['ID' => $this->id])
        ->asArray()
        ->all();
    foreach ($data as ['Parameter' => $parameter, 'Value' => $value]) {
        $this->$parameter = $value;
    }
    //...
}