Skip to content

Commit

Permalink
Merge pull request #302 from strongloop/rename-datamodel-to-persisted…
Browse files Browse the repository at this point in the history
…model

[2.0] Rename DataModel to PersistedModel
  • Loading branch information
bajtos committed Jun 5, 2014
2 parents 93a74f2 + ea5b9d1 commit 71792b1
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 129 deletions.
2 changes: 1 addition & 1 deletion example/client-server/models.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var loopback = require('../../');

var CartItem = exports.CartItem = loopback.DataModel.extend('CartItem', {
var CartItem = exports.CartItem = loopback.PersistedModel.extend('CartItem', {
tax: {type: Number, default: 0.1},
price: Number,
item: String,
Expand Down
31 changes: 28 additions & 3 deletions lib/loopback.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,22 @@ loopback.createModel = function (name, properties, options) {
var BaseModel = options.base || options.super;

if(typeof BaseModel === 'string') {
var baseName = BaseModel;
BaseModel = loopback.getModel(BaseModel);

if (BaseModel === undefined) {
if (baseName === 'DataModel') {
console.warn('Model `%s` is extending deprecated `DataModel. ' +
'Use `PeristedModel` instead.', name);
BaseModel = loopback.PersistedModel;
} else {
console.warn('Model `%s` is extending an unknown model `%s`. ' +
'Using `PersistedModel` as the base.', name, baseName);
}
}
}

BaseModel = BaseModel || loopback.DataModel;
BaseModel = BaseModel || loopback.PersistedModel;

var model = BaseModel.extend(name, properties, options);

Expand Down Expand Up @@ -337,7 +349,20 @@ loopback.autoAttachModel = function(ModelCtor) {
*/

loopback.Model = require('./models/model');
loopback.DataModel = require('./models/data-model');
loopback.PersistedModel = require('./models/persisted-model');

// temporary alias to simplify migration of code based on <=2.0.0-beta3
Object.defineProperty(loopback, 'DataModel', {
get: function() {
var stackLines = new Error().stack.split('\n');
console.warn('loopback.DataModel is deprecated, ' +
'use loopback.PersistedModel instead.');
// Log the location where loopback.DataModel was called
console.warn(stackLines[2]);
return loopback.PersistedModel;
}
});

loopback.Email = require('./models/email');
loopback.User = require('./models/user');
loopback.Application = require('./models/application');
Expand All @@ -358,7 +383,7 @@ var dataSourceTypes = {
};

loopback.Email.autoAttach = dataSourceTypes.MAIL;
loopback.DataModel.autoAttach = dataSourceTypes.DB;
loopback.PersistedModel.autoAttach = dataSourceTypes.DB;
loopback.User.autoAttach = dataSourceTypes.DB;
loopback.AccessToken.autoAttach = dataSourceTypes.DB;
loopback.Role.autoAttach = dataSourceTypes.DB;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var ACLSchema = {
* @inherits Model
*/

var ACL = loopback.DataModel.extend('ACL', ACLSchema);
var ACL = loopback.PersistedModel.extend('ACL', ACLSchema);

ACL.ALL = AccessContext.ALL;

Expand Down
2 changes: 1 addition & 1 deletion lib/models/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function generateKey(hmacKey, algorithm, encoding) {
* @inherits {Model}
*/

var Application = loopback.DataModel.extend('Application', ApplicationSchema);
var Application = loopback.PersistedModel.extend('Application', ApplicationSchema);

/*!
* A hook to generate keys before creation
Expand Down
14 changes: 7 additions & 7 deletions lib/models/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Module Dependencies.
*/

var DataModel = require('./data-model')
var PersistedModel = require('./persisted-model')
, loopback = require('../loopback')
, crypto = require('crypto')
, CJSON = {stringify: require('canonical-json')}
Expand Down Expand Up @@ -45,7 +45,7 @@ var options = {
* @inherits {Model}
*/

var Change = module.exports = DataModel.extend('Change', properties, options);
var Change = module.exports = PersistedModel.extend('Change', properties, options);

/*!
* Constants
Expand All @@ -67,7 +67,7 @@ Change.Conflict = Conflict;
*/

Change.setup = function() {
DataModel.setup.call(this);
PersistedModel.setup.call(this);
var Change = this;

Change.getter.id = function() {
Expand Down Expand Up @@ -497,8 +497,8 @@ Change.prototype.getModel = function(callback) {
* **Note: call `conflict.fetch()` to get the `target` and `source` models.
*
* @param {*} modelId
* @param {DataModel} SourceModel
* @param {DataModel} TargetModel
* @param {PersistedModel} SourceModel
* @param {PersistedModel} TargetModel
* @property {ModelClass} source The source model instance
* @property {ModelClass} target The target model instance
*/
Expand All @@ -516,8 +516,8 @@ function Conflict(modelId, SourceModel, TargetModel) {
*
* @callback {Function} callback
* @param {Error}
* @param {DataModel} source
* @param {DataModel} target
* @param {PersistedModel} source
* @param {PersistedModel} target
*/

Conflict.prototype.models = function(cb) {
Expand Down
6 changes: 3 additions & 3 deletions lib/models/checkpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Module Dependencies.
*/

var DataModel = require('../loopback').DataModel
var PersistedModel = require('../loopback').PersistedModel
, loopback = require('../loopback')
, assert = require('assert');

Expand Down Expand Up @@ -32,10 +32,10 @@ var options = {
* @property sourceId {String} the source identifier
*
* @class
* @inherits {DataModel}
* @inherits {PersistedModel}
*/

var Checkpoint = module.exports = DataModel.extend('Checkpoint', properties, options);
var Checkpoint = module.exports = PersistedModel.extend('Checkpoint', properties, options);

/**
* Get the current checkpoint id
Expand Down
Loading

0 comments on commit 71792b1

Please sign in to comment.