Skip to content

Field with default value not saved on create when using the "fields" option. #3458

@vanwalj

Description

@vanwalj

Hello, as described in the title:

If i define a model with a default value for example in my case a UUID

var Media = sequelize.define('Media', {
        uuid: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true,
            allowNull: false
        },
        someValue: DataTypes.STRING
});

Then, if i create my entity using the fields option

Media.create({someValue: 'some value'}, {
            fields: ['someValue']
});

The field uuid is not "inserted"

INSERT INTO `Media` (`someValue`,`updatedAt`,`createdAt`) VALUES ('some value','2015-04-04 05:41:14','2015-04-04 05:41:14');

But if i set my "defaultValue" field into the fields option

Media.create({someValue: 'some value'}, {
            fields: ['uuid', 'someValue']
});

Everything "works fine"

INSERT INTO `Media` (`uuid`,`someValue`,`updatedAt`,`createdAt`) VALUES ('711544ee-691e-4f73-a9d5-9ef11273fa65','some value','2015-04-04 05:41:14','2015-04-04 05:41:14');

Using Sequelize 2.0.5 with MariaDB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions