Allow app.model() to accept a DataSource instance
This commit is contained in:
parent
3ee0ff5af5
commit
c521b3c386
|
@ -90,7 +90,7 @@ app.disuse = function (route) {
|
|||
*
|
||||
* @param {String} modelName The name of the model to define
|
||||
* @options {Object} config The model's configuration
|
||||
* @property {String} dataSource The `DataSource` to attach the model to
|
||||
* @property {String|DataSource} dataSource The `DataSource` to attach the model to
|
||||
* @property {Object} [options] an object containing `Model` options
|
||||
* @property {Object} [properties] object defining the `Model` properties in [LoopBack Definition Language](http://docs.strongloop.com/loopback-datasource-juggler/#loopback-definition-language)
|
||||
* @end
|
||||
|
@ -545,7 +545,11 @@ function dataSourcesFromConfig(config) {
|
|||
|
||||
function modelFromConfig(name, config, app) {
|
||||
var ModelCtor = require('./loopback').createModel(name, config.properties, config.options);
|
||||
var dataSource = app.dataSources[config.dataSource];
|
||||
var dataSource = config.dataSource;
|
||||
|
||||
if(typeof dataSource === 'string') {
|
||||
dataSource = app.dataSources[dataSource];
|
||||
}
|
||||
|
||||
assert(isDataSource(dataSource), name + ' is referencing a dataSource that does not exist: "'+ config.dataSource +'"');
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
var loopback = require('../');
|
||||
|
||||
describe('hidden properties', function () {
|
||||
beforeEach(function (done) {
|
||||
var app = this.app = loopback();
|
||||
var Product = this.Product = app.model('product', {
|
||||
properties: {
|
||||
secret: {}
|
||||
},
|
||||
dataSource: loopback.memory()
|
||||
});
|
||||
app.listen(done);
|
||||
});
|
||||
|
||||
it('should hide a property remotely', function () {
|
||||
|
||||
});
|
||||
});
|
|
@ -624,81 +624,4 @@ describe('Model', function() {
|
|||
assert.equal(model, acl);
|
||||
});
|
||||
});
|
||||
|
||||
// describe('Model.hasAndBelongsToMany()', function() {
|
||||
// it("TODO: implement / document", function(done) {
|
||||
// /* example -
|
||||
//
|
||||
// */
|
||||
// done(new Error('test not implemented'));
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('Model.remoteMethods()', function() {
|
||||
// it("Return a list of enabled remote methods", function() {
|
||||
// app.model(User);
|
||||
// User.remoteMethods(); // ['save', ...]
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('Model.availableMethods()', function() {
|
||||
// it("Returns the currently available api of a model as well as descriptions of any modified behavior or methods from attached data sources", function(done) {
|
||||
// /* example -
|
||||
// User.attachTo(oracle);
|
||||
// console.log(User.availableMethods());
|
||||
//
|
||||
// {
|
||||
// 'User.all': {
|
||||
// accepts: [{arg: 'filter', type: 'object', description: '...'}],
|
||||
// returns: [{arg: 'users', type: ['User']}]
|
||||
// },
|
||||
// 'User.find': {
|
||||
// accepts: [{arg: 'id', type: 'any'}],
|
||||
// returns: [{arg: 'items', type: 'User'}]
|
||||
// },
|
||||
// ...
|
||||
// }
|
||||
// var oracle = loopback.createDataSource({
|
||||
// connector: 'oracle',
|
||||
// host: '111.22.333.44',
|
||||
// database: 'MYDB',
|
||||
// username: 'username',
|
||||
// password: 'password'
|
||||
// });
|
||||
//
|
||||
// */
|
||||
// done(new Error('test not implemented'));
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('Model.before(name, fn)', function(){
|
||||
// it('Run a function before a method is called', function() {
|
||||
// // User.before('save', function(user, next) {
|
||||
// // console.log('about to save', user);
|
||||
// //
|
||||
// // next();
|
||||
// // });
|
||||
// //
|
||||
// // User.before('delete', function(user, next) {
|
||||
// // // prevent all delete calls
|
||||
// // next(new Error('deleting is disabled'));
|
||||
// // });
|
||||
// // User.beforeRemote('save', function(ctx, user, next) {
|
||||
// // if(ctx.user.id === user.id) {
|
||||
// // next();
|
||||
// // } else {
|
||||
// // next(new Error('must be logged in to update'))
|
||||
// // }
|
||||
// // });
|
||||
//
|
||||
// throw new Error('not implemented');
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// describe('Model.after(name, fn)', function(){
|
||||
// it('Run a function after a method is called', function() {
|
||||
//
|
||||
// throw new Error('not implemented');
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
|
|
@ -66,5 +66,4 @@ describe('remoting - integration', function () {
|
|||
});
|
||||
});
|
||||
|
||||
})
|
||||
;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue