Skip to content

Commit 05cbfc0

Browse files
committed
[BoolJSMongoose#fetchModels] Resolve issues in fetching process
- *Fix* Missing call #pop->#shift - Resolve "this" properties sent after calling "super".
1 parent 2e5f717 commit 05cbfc0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/fetch.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ const { Schema } = mongoose;
66
module.exports = async function (instance, name, Component, connection) {
77
let app = instance.getComponents();
88

9-
let args = [ null, app, { mongoose, Schema } ];
9+
let args = [ null, app, { connection, Schema } ];
1010

1111
let SchemaClass = Function.prototype.bind.apply(Component, args);
12-
let schema = new SchemaClass().__schema;
12+
let _model = new SchemaClass();
13+
let schema = _model.__schema;
14+
15+
const modelProps = Object
16+
.getOwnPropertyNames(_model)
17+
.filter(key => typeof _model[key] !== 'function' && key !== '__schema');
1318

1419
const staticsKeys = Object
1520
.getOwnPropertyNames(Component)
@@ -24,11 +29,17 @@ module.exports = async function (instance, name, Component, connection) {
2429
const methodsKeys = Object
2530
.getOwnPropertyNames(Component.prototype)
2631
.filter(key => typeof Component.prototype[key] === 'function');
27-
methodsKeys.pop();
32+
methodsKeys.shift();
2833

2934
for (let key of methodsKeys) {
3035
schema.methods[key] = function (...args) {
31-
return Component.prototype[key].apply(this, args);
36+
let _this = this;
37+
38+
for (let prop of modelProps) {
39+
_this[prop] = _model[prop];
40+
}
41+
42+
return Component.prototype[key].apply(_this, args);
3243
};
3344
}
3445

0 commit comments

Comments
 (0)