mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-02-01 15:23:03 +00:00
set _module property when get model instance
This commit is contained in:
parent
87acef5880
commit
14998bff45
@ -1098,7 +1098,10 @@ think.model = (superClass, methods, module) => {
|
||||
methods = think.extend({}, think.config('db'), methods);
|
||||
let base = methods.type === 'mongo' ? 'model_mongo' : '';
|
||||
let cls = think.lookClass(superClass, 'model', module, base);
|
||||
return new cls(superClass, methods);
|
||||
let instance = new cls(superClass, methods);
|
||||
//set module for model method used
|
||||
instance._module = module;
|
||||
return instance;
|
||||
}
|
||||
let model = thinkCache(thinkCache.COLLECTION, 'model');
|
||||
if(!model){
|
||||
|
||||
@ -83,7 +83,7 @@ export default class {
|
||||
*/
|
||||
model(name, options){
|
||||
options = think.extend({}, this.config, options);
|
||||
return think.model(name, options);
|
||||
return think.model(name, options, this._module);
|
||||
}
|
||||
/**
|
||||
* get config key
|
||||
|
||||
@ -1999,6 +1999,14 @@ describe('core/think.js', function(){
|
||||
})
|
||||
assert.equal(instance.tablePrefix, 'think_');
|
||||
})
|
||||
it('get model instance, _module', function(){
|
||||
var instance = think.model('test', {
|
||||
host: '127.0.0.1',
|
||||
type: 'mysql'
|
||||
}, 'home')
|
||||
assert.equal(instance.tablePrefix, 'think_');
|
||||
assert.equal(instance._module, 'home');
|
||||
})
|
||||
it('get model instance, mongo', function(){
|
||||
var instance = think.model('test', {
|
||||
host: '127.0.0.1',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user