Sequelize在与多个表相对应的表中添加外键列

时间:2019-01-09 09:45:01

标签: mysql node.js sequelize.js

我有一个数据库结构,其中有4个表,假设是

Table1,Table2,Table3和Table4

表1,2,3之间的关系如下:

        {
"items": [
    {
        "componentType": "NameBox",
        "lable": "name",
        "properties": {
            "type": "string",
            "minLength": 3,
            "desicription": "Enter Your Name"
        }
    },
    {
        "componenetType": "UserNameBox",
        "lable": "username",
        "properties": {
            "type": "string",
            "minLength": 4,
            "maxLength": 8,
            "description": "Enter user name"
        }
    },
    {
        "componenetType": "EmailBox",
        "lable": "email",
        "properties": {
            "type": "string",
            "pattern": "^[a-z0-9]+(\\.[_a-z0-9]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,15})$",
            "description": "Enter email"
        }
    },
    {
        "componenetType": "PasswordBox",
        "lable": "password",
        "properties": {
            "type": "string",
            "pattern": "^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,16}$",
            "description": "Enter password"
        }
    },
    {
        "componentType": "CountryDropDown",
        "lable": "country",
        "properties": {
            "type": "string",
            "enum": [
                "AUS",
                "IN",
                "JP",
                "US",
                "RU",
                "Other"
            ]
        }
    },
    {
        "componenetType": "RadioButton",
        "lable": "gender",
        "properties": {

            "type": "string",
            "anyOf": [
                {
                    "type": "radios",
                    "key": "radios",
                    "enum": [
                        {
                            "value": "male",
                            "name": "Male"
                        },
                        {
                            "value": "female",
                            "name": "Female"
                        }
                    ]
                }


            ]

        }
    },
    {
        "componenetType": "CheckBox",
        "lable": "language",
        "properties": {

            "type": "array",
            "items": {
                "type": "string",
                "enum": [
                    "english",
                    "spanish",
                    "japanese",
                    "french",
                    "hindi"
                ]
            }
        }

    },
    {
        "componenetType": "SubmitButton",
        "lable": "Submit",
        "properties": {

            "type": "submit",
            "title": "Submit"
        }

     }
 ]
}

现在有另一个表Table4,它具有一个键引用,该键引用是table1,table2,table3的外键,即该表看起来像这样

(Table1).hasMany(Table2)
(Table2).hasMany(Table3)

如何定义表之间的关系。在文档中没有提到这样的用例。有没有解决的办法?还是显示我在不定义外键关系的情况下存储数据?

0 个答案:

没有答案