set _module property when get model instance

This commit is contained in:
lichengyin 2015-09-08 20:29:43 +08:00
parent 87acef5880
commit 14998bff45
3 changed files with 13 additions and 2 deletions

View File

@ -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){

View File

@ -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

View File

@ -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',