Add normalized properties to Models
This commit is contained in:
parent
29d1077630
commit
7b8e94019f
37
README.md
37
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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue