我正在使用 Sequelize ORM for MySQL 编写 Node。我需要向 Sequelize 在查询中返回的对象添加一个新字段,但它似乎不起作用。
Category.find({
where: { id: req.params.id },
include: [Item]
}).success(function(category) {
var items = category.items;
var ci = category.items.map(function(item) { return item.id; });
delete category.items; // this works
category.item_ids = ci; // this doesn't
// category['item_ids'] = ci; // this doesn't work as well
res.send({
category: category,
items: items
});
});
Object.isExtensible
在对象上返回 true category
,但我不知道如何实际扩展它