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

Commit 2d5cf42c by Mick Hansen

Merge pull request #1725 from overlookmotel/models-in-sequelize-object

define() stores model in sequelize.models
2 parents 80503f1f 90531bcb
......@@ -5,6 +5,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- Sequelize now returns promises instead of its custom event emitter from most calls. This affects methods that return multiple values (like `findOrCreate` or `findOrInitialize`). If your current callbacks do not accept the 2nd success parameter you might be seeing an array as the first param. Either use `.spread()` for these methods or add another argument to your callback: `.success(instance)` -> `.success(instance, created)`.
- `.success()`/`.done()` and any other non promise methods are now deprecated (we will keep the codebase around for a few versions though). on('sql') persists for debugging purposes.
- Model association calls (belongsTo/hasOne/hasMany) are no longer chainable. (this is to support being able to pass association references to include rather than model/as combinations)
- `define()` stores models in `sequelize.models` Object e.g. `sequelize.models.MyModel`
# v2.0.0-dev11
### Caution: This release contains many changes and is highly experimental
......
......@@ -9,6 +9,7 @@ module.exports = (function() {
ModelManager.prototype.addDAO = function(dao) {
this.daos.push(dao)
this.sequelize.models[dao.name] = dao
return dao
}
......@@ -17,6 +18,7 @@ module.exports = (function() {
this.daos = this.daos.filter(function(_dao) {
return _dao.name != dao.name
})
delete this.sequelize.models[dao.name]
}
ModelManager.prototype.getDAO = function(daoName, options) {
......
......@@ -162,6 +162,7 @@ module.exports = (function() {
} catch(err) {
throw new Error("The dialect " + this.getDialect() + " is not supported.")
}
this.models = {}
this.modelManager = this.daoFactoryManager = new ModelManager(this)
this.transactionManager = new TransactionManager(this)
......
......@@ -417,6 +417,13 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
done()
})
it("adds a new dao to sequelize.models", function(done) {
expect(this.sequelize.models.bar).to.equal(undefined)
var Bar = this.sequelize.define('bar', { title: DataTypes.STRING })
expect(this.sequelize.models.bar).to.equal(Bar)
done()
})
it("overwrites global options", function(done) {
var sequelize = Support.createSequelizeInstance({ define: { collate: 'utf8_general_ci' } })
var DAO = sequelize.define('foo', {bar: DataTypes.STRING}, {collate: 'utf8_bin'})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!