Add normalized properties to Models

This commit is contained in:
Ritchie Martori 2013-06-27 18:26:44 -07:00 committed by Ritchie
parent 29d1077630
commit 7b8e94019f
2 changed files with 69 additions and 0 deletions

View File

@ -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.

View File

@ -432,6 +432,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) {
// /* example -