New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vanwalj opened this Issue Apr 4, 2015 · 3 comments

Comments

3 participants
@vanwalj

vanwalj commented Apr 4, 2015

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.

@mickhansen mickhansen added the bug label Apr 6, 2015

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Apr 6, 2015

Appears to be a bug. Code doesn't take into account non AI PKs for this case.

@lumberj

This comment has been minimized.

lumberj commented Jun 4, 2015

I'm seeing this issue on 2.1.3 with sqlite

@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jun 5, 2015

@lumberj that version should have the fix, you'll need to provide more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment