我有以下代码(简化):
var group = sequelize.define("group", {
id: {type: DataTypes.INTEGER, autoIncrement: false, primaryKey: true},
name: type: DataTypes.STRING,
parentId: DataTypes.INTEGER
}, { classMethods: {
associate: function (models) {
group.belongsToMany(models.item, { as:'items', foreignKey: 'group_id', through: models.group_item_tie });
}}
});
var group_item_tie = sequelize.define("group_item_tie", {}, {freezeTableName: true});
var item = sequelize.define("item", {
spn: { type: DataTypes.INTEGER, autoIncrement: false, primaryKey: true },
}, { classMethods: {
associate: function (models) {
item.belongsToMany(models.group, { foreignKey: 'spn', through: models.group_item_tie });
}}
});
当我尝试返回一些有关系的记录时,让我们这样说:
dbcontext.group.findAll({
where: { id: 6 },
include: [{
model: dbcontext.item,
as: 'items',
attributes: ['spn']
}]
})
我还得到了结果表group_item_tie
中的字段:
[{
"id": 6,
"name": "abc",
"parentId": 5,
"createdAt": "2015-05-06T15:54:58.000Z",
"updatedAt": "2015-05-06T15:54:58.000Z",
"items": [
{ "spn": 1,
"group_item_tie": {
"createdAt": "2015-05-06 15:54:58.000 +00:00",
"updatedAt": "2015-05-06 15:54:58.000 +00:00",
"group_id": 6,
"spn": 1
}
},
{ "spn": 2,
"group_item_tie": {
"createdAt": "2015-05-06 15:54:58.000 +00:00",
"updatedAt": "2015-05-06 15:54:58.000 +00:00",
"group_id": 6,
"spn": 2
}
},
我在生成的sql查询中看到它。如何从select语句中排除那些?我尝试过其他一些事情,但没有成功。
我希望有一些更干净的东西,然后做:
delete item.group_item_tie;
答案 0 :(得分:36)
我将回答自己,因为它可能对将来有用。因此,根据#3664,#2974和#2975,答案如下(感谢 mickhansen ):
$('#stamptext').keyup(function(e){
if($('#previewtext').width() >= $("#stamptextbox").width()){
[what do I do here!?]
}
});
很快就会记录在案。
答案 1 :(得分:2)
我意识到这个线程有点过时了,但是由于在Google搜索结果中排名很高,而且我自己也很难找到答案,因此我想在这里添加它。
如果您使用的是Model.getAssociatedModel()
或Model.$get()
(对于sequelize-typescript),列出的当前答案将不适用于此用例。为了隐藏模型关联,您需要添加joinTableAttributes: []
示例:
Model.getAssociatedModel({
joinTableAttributes: []
})
示例:
Model.$get('property', <any>{
joinTableAttributes: []
});
在撰写本文时,joinTableAttributes
未包括在续集打字稿类型中,因此<any>
答案 2 :(得分:0)
through: {
attributes: []
}
为我工作