Comparing version 0.0.41 to 0.0.42
@@ -34,3 +34,3 @@ var util = require('util'), | ||
this.methods = definition && _.omit(definition,'name','fields','connector','metadata','mappings','actions'); | ||
this._wireMethods(this); | ||
this._wireMethods(); | ||
@@ -61,3 +61,3 @@ if (models.indexOf(this)===-1) { | ||
function curryRequestDispatcher(model, fn, name, scope, request) { | ||
function curryRequestDispatcher(model, fn, name, request) { | ||
if (request && excludeMethods.indexOf(name)===-1) { | ||
@@ -67,3 +67,3 @@ return function() { | ||
try { | ||
return fn.apply(scope, arguments); | ||
return fn.apply(model, arguments); | ||
} | ||
@@ -76,3 +76,3 @@ finally { | ||
else { | ||
return fn.bind(scope); | ||
return fn; | ||
} | ||
@@ -96,3 +96,3 @@ } | ||
Model.prototype._wireMethods = function _wireMethods(model, request) { | ||
Model.prototype._wireMethods = function _wireMethods(request) { | ||
@@ -102,9 +102,9 @@ // Bind functions. | ||
var fn = this[name]; | ||
if (_.isFunction(fn)) { | ||
if (typeof fn === 'function') { | ||
if (this.connector) { | ||
var mapFn = dispatchers[name]; | ||
if (mapFn) { | ||
var cnFn = model[mapFn]; | ||
var cnFn = this[mapFn]; | ||
// we don't have a connector fn, skip it | ||
if (!_.isFunction(cnFn)) { | ||
if (typeof cnFn !== 'function') { | ||
continue; | ||
@@ -114,3 +114,3 @@ } | ||
} | ||
this[name] = curryRequestDispatcher(model, fn, name, this, request); | ||
this[name] = curryRequestDispatcher(this, fn, name, request); | ||
} | ||
@@ -123,6 +123,6 @@ else { | ||
// Bind method functions. | ||
_.each(_.keys(this.methods), function wireMethodIterator(name) { | ||
this.methods && Object.keys(this.methods).forEach(function (name) { | ||
var fn = this.methods[name]; | ||
if (_.isFunction(fn)) { | ||
this[name] = curryRequestDispatcher(model, fn, name, this, request); | ||
if (typeof fn === 'function') { | ||
this[name] = curryRequestDispatcher(this, fn, name, request); | ||
} | ||
@@ -189,14 +189,9 @@ else { | ||
var promise = this.getConnector().createRequest(request, response); | ||
var model = new Model(this.name, null, true); | ||
model.fields = this.fields; | ||
_.merge(model, this); | ||
model.connector = promise; | ||
model.login = promise.login; | ||
model.metadata = this.metadata; | ||
model.methods = this.methods; | ||
model.mappings = this.mappings; | ||
model.autogen = this.autogen; | ||
model.actions = JSON.parse(JSON.stringify(this.actions)); | ||
model._supermodel = this._supermodel; | ||
model._parent = this._parent; | ||
model._wireMethods(model, request); | ||
model._wireMethods(request); | ||
return model; | ||
@@ -250,3 +245,3 @@ }; | ||
model._parent = instance; | ||
model._wireMethods(model); | ||
model._wireMethods(); | ||
return model; | ||
@@ -253,0 +248,0 @@ } |
{ | ||
"name": "api-orm", | ||
"version": "0.0.41", | ||
"version": "0.0.42", | ||
"description": "API Builder ORM", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -205,8 +205,8 @@ var should = require('should'), | ||
}); | ||
function noop() { } | ||
shouldBe = { where: {}, per_page: 10, limit: 10, page: 1, skip: 0 }; | ||
model.query({}, noop); | ||
// Limit and per_page should be interchangeable. | ||
@@ -217,3 +217,3 @@ shouldBe = { per_page: 1, limit: 1, page: 1, skip: 0 }; | ||
model.query({ limit: 2 }, noop); | ||
// Page should translate to skip properly. | ||
@@ -224,3 +224,3 @@ shouldBe = { per_page: 3, limit: 3, page: 3, skip: 6 }; | ||
model.query({ skip: 12, limit: 4 }, noop); | ||
}); | ||
@@ -227,0 +227,0 @@ |
105349
3454