不要怂,就是干,撸起袖子干!

Commit 4181d346 by Jack

Fixed typos and added test.

1 parent 9b34015a
......@@ -119,7 +119,7 @@ module.exports = (function() {
delete result.columns;
});
return results;
} else if (self.isForeignKeysQuery) {
} else if (self.isForeignKeysQuery()) {
result = [];
rows.forEach(function(row) {
var defParts;
......@@ -266,7 +266,7 @@ module.exports = (function() {
Query.prototype.isForeignKeysQuery = function() {
return this.sql.match(/SELECT conname as constraint_name, pg_catalog\.pg_get_constraintdef(r\.oid, true) as condef FROM pg_catalog\.pg_constraint r WHERE r\.conrelid = (SELECT oid FROM pg_class WHERE relname = '.*' LIMIT 1) AND r\.contype = 'f' ORDER BY 1;/g);
}
};
Query.prototype.getInsertIdField = function() {
return 'id';
......
......@@ -249,4 +249,49 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
});
});
});
describe('describeForeignKeys', function() {
beforeEach(function () {
return this.queryInterface.createTable('users', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoincrement: true
},
}).bind(this).then(function () {
return this.queryInterface.createTable('hosts', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoincrement: true
},
owner: {
type: DataTypes.INTEGER,
references: 'users',
referenceKey: 'id',
}
})
})
})
it('should get a list of foreign keys for the table', function (done) {
this.sequelize.query(this.queryInterface.QueryGenerator.getForeignKeysQuery('hosts', this.sequelize.config.database)).complete(function(err, fks) {
expect(err).to.be.null
expect(fks).to.have.length(1)
keys = Object.keys(fks[0]);
if (dialect === "postgres" || dialect === "postgres-native") {
expect(keys).to.have.length(5)
} else if (dialect === "sqlite") {
expect(keys).to.have.length(8)
} else if (dialect === "mysql") {
expect(keys).to.have.length(1)
} else {
console.log("This test doesn't support " + dialect)
}
done()
})
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!