Re-use modelBuilder - correctly fixes lookup

This commit is contained in:
Fabien Franzen 2014-09-04 17:54:42 +02:00
parent 2c0ffee2d3
commit 72930bf20b
4 changed files with 4 additions and 24 deletions

View File

@ -4,12 +4,6 @@ exports.ModelBaseClass = require('./lib/model.js');
exports.GeoPoint = require('./lib/geo.js').GeoPoint;
exports.ValidationError = require('./lib/validations.js').ValidationError;
var dataSources = exports.dataSources = {};
exports.registerDataSource = function(ds) {
dataSources[ds.name] = ds;
};
exports.__defineGetter__('version', function () {
return require('./package.json').version;
});

View File

@ -4,7 +4,6 @@
var assert = require('assert');
var util = require('util');
var i8n = require('inflection');
var jdb = require('../');
var defineScope = require('./scope.js').defineScope;
var mergeQuery = require('./scope.js').mergeQuery;
var ModelBaseClass = require('./model.js');
@ -467,7 +466,7 @@ function findBelongsTo(modelFrom, modelTo, keyTo) {
* @param {String} modelName The model name
* @returns {*} The matching model class
*/
function lookupModel(models, modelName, internal) {
function lookupModel(models, modelName) {
if(models[modelName]) {
return models[modelName];
}
@ -477,15 +476,6 @@ function lookupModel(models, modelName, internal) {
return models[name];
}
}
if (internal) return;
var keys = Object.keys(jdb.dataSources);
for (var k = 0; k < keys.length; k++) {
var ds = jdb.dataSources[keys[k]];
var models = ds.modelBuilder.models;
var model = lookupModel(models, modelName, true);
if (model) return model;
}
}
function lookupModelTo(modelFrom, modelTo, params, singularize) {

View File

@ -10,7 +10,7 @@ var Person, Address;
var Link;
var getTransientSchema = function(settings) {
return new Schema('transient', settings);
return new Schema('transient', settings, db.modelBuilder);
};
describe('relations', function () {
@ -2423,10 +2423,6 @@ describe('relations', function () {
db = getSchema();
tmp = getTransientSchema();
// register here, so transient models
// can lookup related models (polymorphic)
jdb.registerDataSource(db);
Book = db.define('Book', {name: String});
Author = db.define('Author', {name: String});
Reader = db.define('Reader', {name: String});

View File

@ -5,12 +5,12 @@ var assert = require('assert');
var async = require('async');
var should = require('./init.js');
var db, TransientModel, Person, Widget, Item;
var getTransientSchema = function(settings) {
return new Schema('transient', settings);
};
var db, TransientModel, Person, Widget, Item;
describe('Transient connector', function () {
before(function () {