Merge pull request #1271 from strongloop/refactor/core-models
Refactor Model and PersistedModel registration
This commit is contained in:
commit
5a51c7f0fa
|
@ -1,12 +1,13 @@
|
||||||
/*!
|
/*!
|
||||||
* Module Dependencies.
|
* Module Dependencies.
|
||||||
*/
|
*/
|
||||||
var registry = require('./registry');
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var RemoteObjects = require('strong-remoting');
|
var RemoteObjects = require('strong-remoting');
|
||||||
var SharedClass = require('strong-remoting').SharedClass;
|
var SharedClass = require('strong-remoting').SharedClass;
|
||||||
var extend = require('util')._extend;
|
var extend = require('util')._extend;
|
||||||
|
|
||||||
|
module.exports = function(registry) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class for **all models**.
|
* The base class for **all models**.
|
||||||
*
|
*
|
||||||
|
@ -95,7 +96,7 @@ var extend = require('util')._extend;
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Model = module.exports = registry.modelBuilder.define('Model');
|
var Model = registry.modelBuilder.define('Model');
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Called when a model is extended.
|
* Called when a model is extended.
|
||||||
|
@ -809,3 +810,6 @@ Model.ValidationError = require('loopback-datasource-juggler').ValidationError;
|
||||||
|
|
||||||
// setup the initial model
|
// setup the initial model
|
||||||
Model.setup();
|
Model.setup();
|
||||||
|
|
||||||
|
return Model;
|
||||||
|
};
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
* Module Dependencies.
|
* Module Dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Model = require('./model');
|
|
||||||
var registry = require('./registry');
|
|
||||||
var runtime = require('./runtime');
|
var runtime = require('./runtime');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var deprecated = require('depd')('loopback');
|
var deprecated = require('depd')('loopback');
|
||||||
var debug = require('debug')('loopback:persisted-model');
|
var debug = require('debug')('loopback:persisted-model');
|
||||||
|
|
||||||
|
module.exports = function(registry) {
|
||||||
|
|
||||||
|
var Model = registry.Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends Model with basic query and CRUD support.
|
* Extends Model with basic query and CRUD support.
|
||||||
*
|
*
|
||||||
|
@ -26,7 +28,7 @@ var debug = require('debug')('loopback:persisted-model');
|
||||||
* @class PersistedModel
|
* @class PersistedModel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var PersistedModel = module.exports = Model.extend('PersistedModel');
|
var PersistedModel = Model.extend('PersistedModel');
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Setup the `PersistedModel` constructor.
|
* Setup the `PersistedModel` constructor.
|
||||||
|
@ -1443,3 +1445,6 @@ PersistedModel.rectifyChange = function(id, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PersistedModel.setup();
|
PersistedModel.setup();
|
||||||
|
|
||||||
|
return PersistedModel;
|
||||||
|
};
|
||||||
|
|
|
@ -431,8 +431,8 @@ registry.DataSource = DataSource;
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
registry.Model = require('./model');
|
registry.Model = require('./model')(registry);
|
||||||
registry.PersistedModel = require('./persisted-model');
|
registry.PersistedModel = require('./persisted-model')(registry);
|
||||||
|
|
||||||
// temporary alias to simplify migration of code based on <=2.0.0-beta3
|
// temporary alias to simplify migration of code based on <=2.0.0-beta3
|
||||||
Object.defineProperty(registry, 'DataModel', {
|
Object.defineProperty(registry, 'DataModel', {
|
||||||
|
|
Loading…
Reference in New Issue