我使用Sequelize express和Node.js作为后端。我有模型事件和模型买家关系很多很多
模特活动:
module.exports = function (sequelize, DataTypes) {
var Seller = sequelize.define("Seller", { //...
}, {
tableName: 'seller',
timestamps: false,
freezeTableName: true,
classMethods: {
associate: function (models) {
Seller.hasMany(models.Meetings, {foreignKey: 'seller_id'});
Seller.belongsToMany(models.Event, {
through: 'SellerPresent'});
}
}
});
return Seller;
};
模特卖家:
res.render('path', {'results':seller})
我运行查询并使用
发送数据function findIdSeller(selectEvent) {
var match = {
where: {
event: selectEvent
},
// include: {
// model: Seller
// },
include: [{
model: Seller,
nested: false
}],
// plain:true
raw: true
};
return models.Event.findAll(match)
}
exports.findDataSellerPromise = function (selectEvent) {
return findIdSeller(selectEvent).then(function (result) {
return result.map(function(seller) {
console.log('SELLINFO: ', seller);
return seller;
});
});
};
:
{
id: 4,
incoming: 2,
event: 4,
'Sellers.id': 1,
'Sellers.name_firm': 'kdm srl',
'Sellers.site': 'www.terrebasse.com'
}
在我收到的终端中:
{
id: 4,
incoming: 2,
event: 4,
Sellers: {
id': 1,
name_firm: 'kdm srl',
site: 'www.terrebasse.com'
}
}
如何将项目退回:
"use strict";
exports.__esModule = true;
var nativescript_audio_1 = require("nativescript-audio");
var YourClass = (function () {
function YourClass() {
var _this = this;
this._player = new nativescript_audio_1.TNSPlayer();
this._player.initFromFile({
audioFile: '~/audio/song.mp3',
loop: false,
completeCallback: this._trackComplete.bind(this),
errorCallback: this._trackError.bind(this)
}).then(function () {
_this._player.getAudioTrackDuration().then(function (duration) {
// iOS: duration is in seconds
// Android: duration is in milliseconds
console.log("song duration:", duration);
});
});
}
YourClass.prototype.togglePlay = function () {
if (this._player.isAudioPlaying()) {
this._player.pause();
}
else {
this._player.play();
}
};
YourClass.prototype._trackComplete = function (args) {
console.log('reference back to player:', args.player);
// iOS only: flag indicating if completed succesfully
console.log('whether song play completed successfully:', args.flag);
};
YourClass.prototype._trackError = function (args) {
console.log('reference back to player:', args.player);
console.log('the error:', args.error);
// Android only: extra detail on error
console.log('extra info on the error:', args.extra);
};
return YourClass;
}());
exports.YourClass = YourClass;
答案 0 :(得分:1)
从查询中删除raw: true
这将使卖家成为每个事件的实例
像
这样的东西{
//Event1 properties
Sellers: {
// Associated sellers properties
}
}
猜猜我来晚了太晚了..
但对于任何面临类似问题的人来说