gpt4 book ai didi

sequelize.js - SequelizeJS 和关系的问题

转载 作者:行者123 更新时间:2023-12-03 22:42:51 25 4
gpt4 key购买 nike

我想根据关联模型的参数更改模型中的值...

我不知道如何在我的预约模型中获取客户的性别...

var Appointment = db.define('Appointment', {
title: {
type: Types.STRING,
validate: {
len: {
args: [1, 50],
msg: 'Vous devez saisir un titre entre 1 et 50 caractères.'
}
}
},
start: {
type: Types.DATE
},
end: {
type: Types.DATE
},
backgroundColor: {
type: Types.STRING,
defaultValue: 'red'
set: function(value){
// if Customer.gender === 'M' >> this.backgroundColor = 'red'
// if Customer.gender === 'F' >> this.backgroundColor = 'yellow'
}
}
}, {
classMethods:{
associate: function (models) {
Appointment.belongsTo(models.Customer, {as: 'Customer'});
}
}
});

最佳答案

你可以使用:

Appointment.find({ where : {id :1},
include : User })
.success(function(appointment){
console.log(appointment); // visualize your instance
appointment.user.gender;
});

更多信息: https://github.com/sequelize/sequelize/wiki/API-Reference-Model#findAll
寻找选项 [options.include]
也许也是一个很好的答案: sequelize fetching associations on find (1.6)

关于sequelize.js - SequelizeJS 和关系的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25788207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com