Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clear definitions so the can be re-registered

  • Loading branch information...
commit 5c60112a2e9a14015c2f71f44ecb41f441cd463d 1 parent 4d7ec92
@mde mde authored
View
10 lib/base_config.js
@@ -0,0 +1,10 @@
+
+var config = {
+ useTimestamps: true
+, useUTC: true
+, forceCamel: true
+, autoIncrementId: false
+, defaultAdapter: null
+};
+
+module.exports = config;
View
11 lib/index.js
@@ -569,6 +569,17 @@ utils.mixin(model, new (function () {
return obj;
};
+ this.clearDefinitions = function (defs) {
+ var self = this;
+ defs.forEach(function (m) {
+ // Prefer 'name', accept older 'ctorName'
+ var name = m.name || m.ctorName;
+ // Registration may have happened in the model definition file
+ // if using the old templates. Don't re-register
+ delete self[name];
+ });
+ };
+
this.registerDefinitions = function (defs) {
var self = this;
defs.forEach(function (m) {
View
2  test/fixtures/event.js
@@ -19,7 +19,7 @@ Event.prototype.someMethod = function () {
};
Event.findByTitle = function (t, cb) {
- Event.all({title: t}, cb);
+ model.Event.all({title: t}, cb);
};
module.exports.Event = Event;
View
2  test/integration/adapters/shared.js
@@ -1111,7 +1111,7 @@ tests = {
}
// FIXME: This isn't really an integration test
-, 'test Static methods on model': function (next) {
+, 'test static methods on model': function (next) {
model.Event.findByTitle('a', function (err, data) {
assert.equal(1, data.length);
if (err) { throw err; }
View
20 test/integration/adapters/sql/postgres_common.js
@@ -17,11 +17,11 @@ common = new (function () {
adapter = new Adapter(config.postgres);
adapter.once('connect', function () {
- var sql = '';
-
- sql += adapter.generator.dropTable(relations);
- sql += adapter.generator.createTable(relations);
+ var sql = ''
+ , tables = helpers.fixtureNames;
+ sql += adapter.generator.dropTable(tables);
+ sql += adapter.generator.createTable(tables);
adapter.exec(sql, function (err, data) {
if (err) {
throw err;
@@ -31,16 +31,18 @@ common = new (function () {
});
adapter.connect();
- model.adapters = {};
relations.forEach(function (r) {
- model[r].adapter = adapter;
models.push({
- ctorName: r
+ ctorName: r.ctorName
+ , ctor: r.ctor
});
});
-
- console.log('REGISTERING');
+ model.clearDefinitions(models);
model.registerDefinitions(models);
+ model.adapters = {};
+ relations.forEach(function (r) {
+ model[r.ctorName].adapter = adapter;
+ });
return adapter;
};
Please sign in to comment.
Something went wrong with that request. Please try again.