Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用sequelize将两个或三个sql查询结果合并到一个JS变量中_Javascript_Mysql_Express_Sequelize.js - Fatal编程技术网

Javascript 如何使用sequelize将两个或三个sql查询结果合并到一个JS变量中

Javascript 如何使用sequelize将两个或三个sql查询结果合并到一个JS变量中,javascript,mysql,express,sequelize.js,Javascript,Mysql,Express,Sequelize.js,我正在使用sequelize对sql执行两种不同的查询。但在最后,我想将两个查询的结果合并到一个JS对象中,并将其发送到前端 export const getOrganizerPublicData = async (payload) => { const sqlOptions={raw: true}; // this option removes all sql specific values, and gives just table data in simple js object

我正在使用sequelize对sql执行两种不同的查询。但在最后,我想将两个查询的结果合并到一个JS对象中,并将其发送到前端

export const getOrganizerPublicData = async (payload) => {
  const sqlOptions={raw: true}; // this option removes all sql specific values, and gives just table data in simple js object format.
  const data = await findOneByCondition({ProfileLink: payload}, db.organization_profiles, sqlOptions);
  if(!data){
    throw new Error(Message.recordNotFound);
  }
  const completedEvents = await findAllEventsWithConditionIncludes({EventStatus: 1, EventOrganizerID: data.UserId }, db.events, sqlOptions, attrP);
  const activeEvents = await findAllEventsWithConditionIncludes({EventStatus: 4, EventOrganizerID: data.UserId}, db.events, sqlOptions,);
  const finalData = {
    ...data,
    activeEvents,
    completedEvents
  }
  return finalData;
}
目前,在使用raw时,我在JS对象类型中获取值,但include中的数据在JS类型中没有正确解析 以下是输出:

"data": {
        "ID": 2,
        "UserId": 2,
        "IREmployeeID": "12355",
        "OrganizationName": "Astro Veda",
        "About": "dgsdgsdfsf",
        "ProfileLink": "BoredBalloon",
        "ContactPersonFirstName": "Shuo",
        "ContactPersonLastName": "",
        "LegalEntityId": 1,
        "CreatedBy": 2,
        "ModifiedBy": 2,
        "IsActive": 1,
        "UpdateProfileVisited": 1,
        "createdAt": "2020-09-21T05:35:27.000Z",
        "updatedAt": "2020-09-21T08:25:20.000Z",
        "activeEvents": [],
        "completedEvents": [
            {
                "EventId": 3,
                "EventLocationID": 3,
                "EventSportsID": 5,
                "EventTitle": "aaaaaa",
                "EventDescription": "",
                "Surface": "0",
                "EventLocationType": "1",
                "FirstNameNLastName": "",
                "EventStartDate": "2020-10-01T06:15:18.000Z",
                "EventEndDate": "2020-10-03T06:15:18.000Z",
                "location.VenueName": "gtyui",
                "location.Address": "shree nagr chapra 12345, Jagiraha, Laranpur, Bihar 801303, India",
                "location.Locality": "Jagiraha",
                "location.City": "Nalanda",
                "location.State": "Bihar",
                "location.Country": "",
                "location.ZipCode": "801303",
                "sports_type.Name": "Walking"
            },
            {
                "EventId": 4,
                "EventLocationID": 4,
                "EventSportsID": 5,
                "EventTitle": "bbbbbbbb",
                "EventDescription": "",
                "Surface": "0",
                "EventLocationType": "1",
                "FirstNameNLastName": "",
                "EventStartDate": "2020-10-01T06:15:18.000Z",
                "EventEndDate": "2020-10-03T06:15:18.000Z",
                "location.VenueName": "Delhi",
                "location.Address": "Delhi, India",
                "location.Locality": "Delhi",
                "location.City": "Nalanda",
                "location.State": "Delhi",
                "location.Country": "",
                "location.ZipCode": "801303",
                "sports_type.Name": "Walking"
            }
        ]
    },
如果我删除{raw:true},我会得到正确的js格式的值,但我无法将其放在一个变量中发送到前端

如果尝试在没有原始标志的情况下将所有结果放在一起,则会出现此错误

"message": "Converting circular structure to JSON\n    --> starting at object with constructor 'Sequelize'\n    |     property 'dialect' -> object with constructor 'MysqlDialect'\n    --- property 'sequelize' closes the circle"
"message": "Converting circular structure to JSON\n    --> starting at object with constructor 'Sequelize'\n    |     property 'dialect' -> object with constructor 'MysqlDialect'\n    --- property 'sequelize' closes the circle"