如何将完整的对象workstation
放入另一个对象userWorkstationSchedule
?
代码:
Workstation.js
module.exports = {
tableName: 'workstation',
attributes: {
name: { type: 'string', required: true, maxLength: 100, columnType: 'VARCHAR(100)' },
company: { model: 'company', required: true },
workDates: { collection: 'workstationSchedule', via: 'workstation'},
reservedDates: {collection: 'userWorkstationSchedule', via: 'workstation'},
}
}
reservedDates
属性从userWorkstationSchedule
对象接收数据UserWorkstationSchedule.js
module.exports = {
tableName: 'user_workstation_schedule',
attributes: {
presenceSchedules: { collection: 'presenceschedule', via: 'userWorkstationSchedule' },
workstation: {collection: 'workstation', via: 'reservedDates'},
}
}
您不需要放入“完整对象”,他已经在里面,这就是Sails.js和任何ORM的强大功能。
数据感染是异步且“惰性”的。 (有关LazyLoading的更多信息)
ORM仅加载绝对必要的内容,而不是所有链接的关联。
在Sails.js中,当需要特定数据时,需要通过.populate()方法填充它。
var userWorkstationSchedule = await UserWorkstationSchedule.find().populate('workstation');
您可以在Sails.JS Documentation中找到有关填充的更多信息>