commit
e49eb47e36
|
@ -418,6 +418,12 @@ ModelBaseClass.toString = function() {
|
||||||
* @returns {Object} returns Plain JSON object
|
* @returns {Object} returns Plain JSON object
|
||||||
*/
|
*/
|
||||||
ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removeProtected) {
|
ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removeProtected) {
|
||||||
|
if (typeof onlySchema === 'object' && onlySchema != null) {
|
||||||
|
var options = onlySchema;
|
||||||
|
onlySchema = options.onlySchema;
|
||||||
|
removeHidden = options.removeHidden;
|
||||||
|
removeProtected = options.removeProtected;
|
||||||
|
}
|
||||||
if (onlySchema === undefined) {
|
if (onlySchema === undefined) {
|
||||||
onlySchema = true;
|
onlySchema = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,8 +133,8 @@ describe('ModelBuilder', function() {
|
||||||
|
|
||||||
// Predefined property bio should be kept
|
// Predefined property bio should be kept
|
||||||
user.toObject().should.have.property('bio', 'me');
|
user.toObject().should.have.property('bio', 'me');
|
||||||
user.toObject(true).should.have.property('bio', 'me');
|
user.toObject({onlySchema: true}).should.have.property('bio', 'me');
|
||||||
user.toObject(false).should.have.property('bio', 'me');
|
user.toObject({onlySchema: false}).should.have.property('bio', 'me');
|
||||||
|
|
||||||
done(null, User);
|
done(null, User);
|
||||||
});
|
});
|
||||||
|
|
|
@ -83,7 +83,9 @@ export declare class DataSource {
|
||||||
|
|
||||||
DataAccessObject: AnyObject & {prototype: AnyObject};
|
DataAccessObject: AnyObject & {prototype: AnyObject};
|
||||||
|
|
||||||
constructor(name?: string, settings?: Options, modelBuilder?: ModelBuilder);
|
constructor(name: string, settings?: Options, modelBuilder?: ModelBuilder);
|
||||||
|
|
||||||
|
constructor(settings?: Options, modelBuilder?: ModelBuilder);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
connectorModule: Connector,
|
connectorModule: Connector,
|
||||||
|
|
|
@ -92,7 +92,7 @@ export declare class ModelDefinition extends EventEmitter implements Schema {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base model class
|
* Base class for LoopBack 3.x models
|
||||||
*/
|
*/
|
||||||
export declare class ModelBase {
|
export declare class ModelBase {
|
||||||
static dataSource?: DataSource;
|
static dataSource?: DataSource;
|
||||||
|
@ -135,15 +135,16 @@ export declare class ModelBase {
|
||||||
static getUpdateOnlyProperties(): string[];
|
static getUpdateOnlyProperties(): string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model class: base class for all persistent objects.
|
* Constructor for ModelBase
|
||||||
*
|
*
|
||||||
* `ModelBaseClass` mixes `Validatable` and `Hookable` classes methods
|
* NOTE: We have to use `constructor(...args: any[]);` so that it can be used
|
||||||
|
* for `return class extends superClass`.
|
||||||
*
|
*
|
||||||
* @class
|
|
||||||
* @param {AnyObject} data Initial object data
|
* @param {AnyObject} data Initial object data
|
||||||
* @param {Options} options An object to control the instantiation
|
* @param {Options} options An object to control the instantiation
|
||||||
*/
|
*/
|
||||||
constructor(data: AnyObject, options?: Options);
|
constructor(...args: any[]);
|
||||||
|
// constructor(data: AnyObject, options?: Options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the model instance to a plain json object
|
* Convert the model instance to a plain json object
|
||||||
|
@ -160,20 +161,17 @@ export declare class ModelBase {
|
||||||
* Convert model instance to a plain JSON object.
|
* Convert model instance to a plain JSON object.
|
||||||
* Returns a canonical object representation (no getters and setters).
|
* Returns a canonical object representation (no getters and setters).
|
||||||
*
|
*
|
||||||
* @param {boolean} onlySchema Restrict properties to dataSource only.
|
* @param options Options for the conversion
|
||||||
|
* @property {boolean} onlySchema Restrict properties to dataSource only.
|
||||||
* Default is false. If true, the function returns only properties defined
|
* Default is false. If true, the function returns only properties defined
|
||||||
* in the schema; Otherwise it returns all enumerable properties.
|
* in the schema; Otherwise it returns all enumerable properties.
|
||||||
* @param {boolean} removeHidden Boolean flag as part of the transformation.
|
* @property {boolean} removeHidden Boolean flag as part of the transformation.
|
||||||
* If true, then hidden properties should not be brought out.
|
* If true, then hidden properties should not be brought out.
|
||||||
* @param {boolean} removeProtected Boolean flag as part of the transformation.
|
* @property {boolean} removeProtected Boolean flag as part of the transformation.
|
||||||
* If true, then protected properties should not be brought out.
|
* If true, then protected properties should not be brought out.
|
||||||
* @returns {object} returns Plain JSON object
|
* @returns {object} returns Plain JSON object
|
||||||
*/
|
*/
|
||||||
toObject(
|
toObject(options?: Options): AnyObject;
|
||||||
onlySchema?: boolean,
|
|
||||||
removeHidden?: boolean,
|
|
||||||
removeProtected?: boolean,
|
|
||||||
): AnyObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a property on the model.
|
* Define a property on the model.
|
||||||
|
|
Loading…
Reference in New Issue