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

Commit 67e713f3 by Sascha Depold

Merge branch 'master' into milestones/2.0.0

2 parents dd38ee5a 7c417a50
......@@ -74,6 +74,7 @@
- [FEATURE] Model#find() / Model#findAll() is now working with strings. [#855](https://github.com/sequelize/sequelize/pull/855). Thanks to whito.
- [FEATURE] Shortcut method for getting a defined model. [#868](https://github.com/sequelize/sequelize/pull/868). Thanks to jwilm.
- [FEATURE] Added Sequelize.fn() and Sequelize.col() to properly call columns and functions within Sequelize. [#882](https://github.com/sequelize/sequelize/pull/882). thanks to janmeier
- [FEATURE] Sequelize.import supports relative paths. [#901](https://github.com/sequelize/sequelize/pull/901). thanks to accerqueira.
- [REFACTORING] hasMany now uses a single SQL statement when creating and destroying associations, instead of removing each association seperately [690](https://github.com/sequelize/sequelize/pull/690). Inspired by [#104](https://github.com/sequelize/sequelize/issues/104). janmeier
- [REFACTORING] Consistent handling of offset across dialects. Offset is now always applied, and limit is set to max table size of not limit is given [#725](https://github.com/sequelize/sequelize/pull/725). janmeier
- [REFACTORING] Moved Jasmine to Buster and then Buster to Mocha + Chai. sdepold and durango
......
var url = require("url")
, Path = require("path")
, Utils = require("./utils")
, DAOFactory = require("./dao-factory")
, DataTypes = require('./data-types')
......@@ -215,6 +216,16 @@ module.exports = (function() {
}
Sequelize.prototype.import = function(path) {
// is it a relative path?
if (url.parse(path).pathname.indexOf('/') !== 0) {
// make path relative to the caller
var callerFilename = Utils.stack()[1].getFileName()
, callerMatch = callerFilename.match(/(.+\/).+?$/)
, callerPath = callerMatch[1]
path = Path.resolve(callerPath, path)
}
if (!this.importCache[path]) {
var defineCall = require(path)
this.importCache[path] = defineCall(this, DataTypes)
......
......@@ -452,6 +452,18 @@ var Utils = module.exports = {
return subClass;
},
stack: function() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error();
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
},
now: function(dialect) {
var now = new Date()
if(dialect != "postgres") now.setMilliseconds(0)
......
......@@ -375,11 +375,17 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
describe('import', function() {
it("imports a dao definition from a file", function(done) {
it("imports a dao definition from a file absolute path", function(done) {
var Project = this.sequelize.import(__dirname + "/assets/project")
expect(Project).to.exist
done()
})
it("imports a dao definition from a file relative path", function(done) {
var Project = this.sequelize.import("assets/project")
expect(Project).to.exist
done()
})
})
describe('define', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!