Skip to content
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
Closed

Comments

@vanwalj
Copy link

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
Copy link
Contributor

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

@alandotcom
Copy link

I'm seeing this issue on 2.1.3 with sqlite

@mickhansen
Copy link
Contributor

@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
Projects
None yet
Development

No branches or pull requests

3 participants