Skip to content

Commit

Permalink
fix: base type wont work after ENUM model is synced (#8851)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushantdhiman committed Jan 8, 2018
1 parent bf7a55b commit d98d8bd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/query-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ class QueryInterface {
.tap(() => {
// If ENUM processed, then refresh OIDs
if (promises.length) {
return this.sequelize.dialect.connectionManager._refreshDynamicOIDs()
.then(() => {
return this.sequelize.refreshTypes(DataTypes.postgres);
});
return this.sequelize.dialect.connectionManager._refreshDynamicOIDs();
}
})
.then(() => {
Expand Down
5 changes: 3 additions & 2 deletions test/integration/data-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
return Sequelize.ABSTRACT.prototype.stringify.apply(this, arguments);
});

current.refreshTypes();

const User = current.define('user', {
field: Type
}, {
timestamps: false
});

return current.sync({ force: true }).then(() => {

current.refreshTypes();

return User.create({
field: value
});
Expand Down
50 changes: 50 additions & 0 deletions test/integration/dialects/postgres/regressions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../../support'),
Sequelize = Support.Sequelize,
dialect = Support.getTestDialect();

if (dialect.match(/^postgres/)) {
describe('[POSTGRES Specific] Regressions', () => {
it('properly fetch OIDs after sync, #8749', function() {
const User = this.sequelize.define('User', {
active: Sequelize.BOOLEAN
});

/**
* This Model is important, sync will try to fetch OIDs after each ENUM model sync
* Having ENUM in this model will force OIDs re-fetch
* We are testing that OID refresh keep base type intact
*/
const Media = this.sequelize.define('Media', {
type: Sequelize.ENUM([
'image', 'video', 'audio'
])
});

User.hasMany(Media);
Media.belongsTo(User);

return this.sequelize
.sync({ force: true })
.then(() => User.create({ active: true }))
.then(user => {
expect(user.active).to.be.true;
expect(user.get('active')).to.be.true;

return User.findOne();
})
.then(user => {
expect(user.active).to.be.true;
expect(user.get('active')).to.be.true;

return User.findOne({ raw: true });
})
.then(user => {
expect(user.active).to.be.true;
});
});
});
}

0 comments on commit d98d8bd

Please sign in to comment.