diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 511488c2..1d698447 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -100,6 +100,15 @@ AbstractClass.defineProperty = function (prop, params) { this.schema.defineProperty(this.modelName, prop, params); }; +AbstractClass.whatTypeName = function (propName) { + var ds = this.schema.definitions[this.modelName]; + return ds.properties[propName].type.name; +}; + +AbstractClass.prototype.whatTypeName = function (propName) { + return this.constructor.whatTypeName(propName); +}; + /** * @param data [optional] * @param callback(err, obj) diff --git a/test/common_test.js b/test/common_test.js index 34c180b2..379f8a16 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -415,6 +415,15 @@ function testOrm(schema) { }); }); + it('should return type of property', function (test) { + test.equal(Post.whatTypeName('title'), 'String'); + test.equal(Post.whatTypeName('content'), 'Text'); + var p = new Post; + test.equal(p.whatTypeName('title'), 'String'); + test.equal(p.whatTypeName('content'), 'Text'); + test.done(); + }); + function allTestsDone() { schema.disconnect(); console.log('Test done in %dms\n', Date.now() - start);