@@ -6,10 +6,15 @@ const { Schema } = mongoose;
6
6
module . exports = async function ( instance , name , Component , connection ) {
7
7
let app = instance . getComponents ( ) ;
8
8
9
- let args = [ null , app , { mongoose , Schema } ] ;
9
+ let args = [ null , app , { connection , Schema } ] ;
10
10
11
11
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' ) ;
13
18
14
19
const staticsKeys = Object
15
20
. getOwnPropertyNames ( Component )
@@ -24,11 +29,17 @@ module.exports = async function (instance, name, Component, connection) {
24
29
const methodsKeys = Object
25
30
. getOwnPropertyNames ( Component . prototype )
26
31
. filter ( key => typeof Component . prototype [ key ] === 'function' ) ;
27
- methodsKeys . pop ( ) ;
32
+ methodsKeys . shift ( ) ;
28
33
29
34
for ( let key of methodsKeys ) {
30
35
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 ) ;
32
43
} ;
33
44
}
34
45
0 commit comments