diff --git a/README.md b/README.md index 3b331579..608c2620 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,43 @@ Validate the model instance. } }); +#### Model.properties + +The an object containing a normalized set of properties supplied to `asteroid.createModel(name, properties)`. + +Example: + + var props = { + a: String, + b: {type: 'Number'}, + c: {type: 'String', min: 10, max: 100}, + d: Date, + e: asteroid.GeoPoint + }; + + var MyModel = asteroid.createModel('foo', props); + + console.log(MyModel.properties); + +Outputs: + + { + "a": {type: String}, + "b": {type: Number}, + "c": { + "type": String, + "min": 10, + "max": 100 + }, + "d": {type: Date}, + "e": {type: GeoPoint}, + "id": { + "id": 1 + } + } + +assert(MyModel.properties); + #### Model.attachTo(dataSource) Attach a model to a [DataSource](#data-source). Attaching a [DataSource](#data-source) updates the model with additional methods and behaviors. diff --git a/test/model.test.js b/test/model.test.js index 60a7b659..44bad7cf 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -431,6 +431,38 @@ describe('Model', function() { }); }); }); + + describe('Model.properties', function(){ + it('Normalized properties passed in originally by asteroid.createModel().', function() { + var props = { + s: String, + n: {type: 'Number'}, + o: {type: 'String', min: 10, max: 100}, + d: Date, + g: asteroid.GeoPoint + }; + + var MyModel = asteroid.createModel('foo', props); + + Object.keys(MyModel.properties).forEach(function (key) { + var p = MyModel.properties[key]; + var o = MyModel.properties[key]; + assert(p); + assert(o); + assert(typeof p.type === 'function'); + + if(typeof o === 'function') { + // the normalized property + // should match the given property + assert( + p.type.name === o.name + || + p.type.name === o + ) + } + }); + }); + }); // describe('Model.hasAndBelongsToMany()', function() { // it("TODO: implement / document", function(done) {