sequelize icon indicating copy to clipboard operation
sequelize copied to clipboard

Many-to-many join table Date attribute not a JavaScript Date

Open publickeating opened this issue 12 years ago • 2 comments

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?

publickeating avatar Dec 01 '14 20:12 publickeating

I'm using v2.0.0.rc1 and sqlite.

publickeating avatar Dec 01 '14 20:12 publickeating

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 :)

mickhansen avatar Dec 02 '14 07:12 mickhansen