Javascript Sequelize.js joinTableAttributes不工作
我有由sequelize关联自动生成的用户、通知和NotificationsUsers表。我可以向用户获取所有通知,但我希望在关联表中存储“读取”字段TRUE或FALSE值。到目前为止,这一切都已设置,但我无法从关联表中提取“读取”字段 我的代码-Javascript Sequelize.js joinTableAttributes不工作,javascript,node.js,sequelize.js,Javascript,Node.js,Sequelize.js,我有由sequelize关联自动生成的用户、通知和NotificationsUsers表。我可以向用户获取所有通知,但我希望在关联表中存储“读取”字段TRUE或FALSE值。到目前为止,这一切都已设置,但我无法从关联表中提取“读取”字段 我的代码- Usr.getNotifications({where: ['Notifications.createdAt >= ?', datetime], joinTableAttributes: ['read']}).success(function(
Usr.getNotifications({where: ['Notifications.createdAt >= ?', datetime], joinTableAttributes: ['read']}).success(function(notes) {
defer.resolve(notes);
});
哪个运行此查询-
SELECT `Notifications`.*, `NotificationsUsers`.`read` as `NotificationsUser.read` FROM `Notifications`, `NotificationsUsers` WHERE `NotificationsUsers`.`UserId` = 1 AND `NotificationsUsers`.`NotificationId` = `Notifications`.`id` AND Notifications.createdAt >= '0000-00-00 00:00:00';
我得到的只是通知表字段。我得到的一个结果的例子-
{ dataValues:
{ id: 7,
type: 'Warranty',
title: 'Warranty Request From Jim Bob',
text: 'My sink is drippy. I don\'t like drippy sinks.' },
_previousDataValues:
{ id: undefined,
type: undefined,
title: undefined,
text: undefined },
__options:
{ timestamps: true,
createdAt: 'createdAt',
updatedAt: 'updatedAt',
deletedAt: 'deletedAt',
instanceMethods: {},
classMethods: {},
validate: {},
freezeTableName: false,
underscored: false,
syncOnAssociation: true,
paranoid: false,
whereCollection: [Object],
schema: null,
schemaDelimiter: '',
language: 'en',
defaultScope: null,
scopes: null,
hooks: [Object],
omitNull: false,
uniqueKeys: {},
hasPrimaryKeys: false },
options: { isNewRecord: false, isDirty: false },
hasPrimaryKeys: false,
selectedValues:
{ id: 7,
type: 'Warranty',
title: 'Warranty Request From Jim Bob',
text: 'My sink is drippy. I don\'t like drippy sinks.',
createdAt: Fri Sep 05 2014 11:18:40 GMT-0500 (CDT),
updatedAt: Fri Sep 05 2014 11:18:40 GMT-0500 (CDT) },
__eagerlyLoadedAssociations: [],
isNewRecord: false,
NotificationsUser:
{ dataValues: [Object],
_previousDataValues: [Object],
__options: [Object],
options: [Object],
hasPrimaryKeys: true,
selectedValues: [Object],
__eagerlyLoadedAssociations: [],
isNewRecord: false } }
根据这些信息,有什么建议我可能做错了什么?为什么我不能获取NotificationsUsers.read字段?读取字段应该在notes.NotificationUser.read中。谢谢!我以前没有注意到这一点。另一方面:where记录了您必须将原始查询传递给生成的get方法而不是对象的where?