我想知道使用#!/usr/bin/python
X_Variable_1, X_Variable_2, X_Variable_3, *_ = [line.rstrip() for line in open("FILENAME").readlines()]
所以使用Sequelize我不能在Promise.all
中添加hasOne
,因为它会给我多个相同符号的结果。
所以我的代码看起来像这样
finaAll
但是我的所有价格都来自我的数据库
Symbol.findAll({
where: {
symbol: ["AAPL", "ORCL", "MSFT", "CSCO"]
},
include: [{
as: "price", // this is hasOne association
model: Price // this is separate model for prices
}],
order: [ // here I am ordering prices by createdAt DESC to get latest price
[{ as: "price", model: Price }, "createdAt", "DESC"]
]
});
所以我认为唯一的解决方案是使用 [{
"symbol": "AAPL",
"price": {
"id": 41669338,
"open": 143.729996,
"high": 144.179993,
"low": 143.270004,
"close": 143.339996,
"volume": 16621300,
"adjClose": 143.339996,
"createdAt": "2017-04-07T00:00:00.000Z",
"companyId": 13,
"updatedAt": "2017-04-07T00:00:00.000Z"
}
},
{
"symbol": "AAPL",
"price": {
"id": 41663996,
"open": 144.289993,
"high": 144.520004,
"low": 143.449997,
"close": 143.660004,
"volume": 21118000,
"adjClose": 143.660004,
"createdAt": "2017-04-06T00:00:00.000Z",
"companyId": 13,
"updatedAt": "2017-04-06T00:00:00.000Z"
}
},
{
"symbol": "AAPL",
"price": {
"id": 41656633,
"open": 144.220001,
"high": 145.460007,
"low": 143.809998,
"close": 144.020004,
"volume": 27481500,
"adjClose": 144.020004,
"createdAt": "2017-04-05T00:00:00.000Z",
"companyId": 13,
"updatedAt": "2017-04-05T00:00:00.000Z"
}
},
... // omitted
和include findOne
,如下所示
Promise.all
这给了我正确的结果,但我想知道这是我的案例的好方法,还是有更好的方法呢?
提前致谢!