Skip to content

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

Closed

Description

@publickeating

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?

Activity

  1. publickeating commented on Dec 1, 2014

    @publickeating
    Author

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

  2. mickhansen commented on Dec 2, 2014

    @mickhansen
    Contributor

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

  3. added
    type: bug
    on Dec 2, 2014
  4. added a commit that references this issue on Jul 31, 2015
    c0ff86f
  5. added 2 commits that reference this issue on Nov 9, 2015
    c076ba2
    484c0c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions