sequelize
sequelize copied to clipboard
Many-to-many join table Date attribute not a JavaScript Date
I have something similar to the following,
File = sequelize.define('File', {
createdOn: DataTypes.Date
});
Group = sequelize.define('Group', {
createdOn: DataTypes.Date
});
FileGroup = sequelize.define('FileGroup', {
availableOn: DataTypes.Date
}, {
tableName: 'file_group'
});
File.hasMany(Group, { through: FileGroup });
Group.hasMany(File, { through: FileGroup });
The problem is that when I load one side of the relationship, with its eagerly loaded associated records, some of the date attributes aren't Date objects.
For example,
File.find({ where: { id: 1 }, include: [Group] })
.then(function (file) {
console.log(typeof file.createdOn); // object
console.log(typeof file.Group.createdOn); // string
console.log(typeof file.Group.file_group.availableOn); // string
});
I would have expected Group.createdOn and Group.file_group.availableOn to have been Date objects. Is this a bug?
I'm using v2.0.0.rc1 and sqlite.
This is likely a sqlite specific bug (iirc there's some special parsing for sqlite that's given us problems before).
A bug never the less. Copy-pastable piece of code or unit test is as always, appreciated :)