多个表加入节点js中的sequelize问题

时间:2019-09-03 18:49:14

标签: node.js sequelize.js

我有6张桌子 员工,薪水,扣除额,扣除类型,津贴,津贴类型

这是与图的表关系 enter image description here

我不明白如何创建联接查询

Sub SPLIT()

Dim main As Worksheet
Dim lastrow As Long

Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim FolderName As String

Set xWb = Application.ThisWorkbook

mBefore = Format(DateAdd("m", -1, Date), "MMM yy")
mPrevious = Format(DateAdd("m", -1, Date), "MMM yy")
Set main = Sheets("Global")
main.Activate

'ActiveSheet.name = "Global"
'Set main = Sheets("Global")

'Calculation of last line
lastrow = main.Cells(Rows.Count, "l").End(xlUp).Row
'MsgBox lastrow

Set FDWDownload1 = Sheets("Global")

Sheets.Add(before:=Sheets("Global")).name = "List"

Set Ref = Sheets("List")

'Creates the table
FDWDownload1.Range("L" & StartPointRow + 1 & ":L" & lastrow).Copy
        Ref.Activate
        Ref.Range("B2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
        Range("B:B").RemoveDuplicates Columns:=1
        Application.CutCopyMode = False

        RefLastRow = Ref.Cells(Rows.Count, "B").End(xlUp).Row
        FDWDownload1.Activate


If RefLastRow > 0 Then
            'For the second row to the end of the table on the References tab
            For i = 3 To RefLastRow
                'Copy the header from the download
                FDWDownload1.Range("A1:P1").Copy

            'Add a new sheet placed after the sheet "Global" & name it according to the reference table
                Sheets.Add(after:=Sheets("Global")).name = Ref.Range("B" & i)
                Set ws = Application.ActiveSheet

                'Paste the header into each newly created sheet
                ws.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                ws.Range("A1").PasteSpecial Paste:=xlPasteFormats

                  'Get the number of the last row on the newly created sheet
                ForLastRow = ws.Cells(Rows.Count, "L").End(xlUp).Row

                'As the download is grouped in Product Line order find the first and last row of the Product according to the worksheet name
                    With FDWDownload1
                        FDWDownload1.Activate
                        k = .Range("L:L").Find(what:=ws.name, after:=.Range("L1")).Row
                        l = .Range("L:L").Find(what:=ws.name, after:=.Range("L1"), searchdirection:=xlPrevious).Row
                    End With
                Range("A" & k & ":O" & l).Copy
                ws.Activate
                ws.Range("A" & ForLastRow + 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                Columns("A:P").EntireColumn.AutoFit
                Columns("A:O").AutoFilter
                Range("A:O").Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlYes

                ActiveSheet.name = ws.name & " " & "GRIR" & " " & mBefore

Next i
        Else
        End If

End Sub

这是我的查找查询

Employee.belongsTo(Salary, {  foreignKey: 'employee_id' });
Salary.belongsToMany(Deduction,    {foreignKey: 'salary_id' });
Deduction.belongsToMany(DeductionType,    {foreignKey:   'deduction_type_id' });
Salary.belongsToMany(Allowance,    {foreignKey: 'salary_id' });
Allowance.belongsToMany(AllowanceType,    {foreignKey: 'allowance_type_id' });

这是我期望的sql join查询

const payRunData = Employee.findAll({
    include: [{
        model: Salary, attributes: ['salary_id', 'basic_salary'],
        include: [
            {
                model: Deduction, attributes: ['amount'],
                include: [{
                    model: DeductionType, attributes: ['epf_enable', 'type', 'pre_tax', 'pay_run_editable'],
                }]
            },
            {
                model: Allowance, attributes: ['amount'],
                include: [{
                    model: AllowanceType, attributes: ['epf_enable', 'type', 'payee_enable', 'pay_run_editable'],
                }]
            }
        ]
    }
    ],
    attributes: ['employee_id', 'given_names'],
});

执行此操作时,它会返回此错误

  

salary.belongsToMany(deduction)要求通过选项,传递一个   字符串或模型”

请帮助我解决这个问题

0 个答案:

没有答案