2015-04-24 09:28:50 +09:00
|
|
|
/**
|
|
|
|
* Add an additional field to a schema.
|
|
|
|
* @param {Object} field
|
|
|
|
*/
|
|
|
|
Meteor.Collection.prototype.registerField = function (field) {
|
|
|
|
|
|
|
|
var collection = this;
|
|
|
|
var fieldSchema = {};
|
|
|
|
|
|
|
|
fieldSchema[field.propertyName] = field.propertySchema;
|
|
|
|
|
|
|
|
// add field schema to collection schema
|
|
|
|
collection.attachSchema(fieldSchema);
|
2015-04-27 09:55:29 +09:00
|
|
|
}
|
|
|
|
|
2015-04-27 10:30:47 +09:00
|
|
|
/**
|
|
|
|
* Remove a field from a schema.
|
|
|
|
* @param {String} fieldName
|
|
|
|
*/
|
|
|
|
Meteor.Collection.prototype.removeField = function (fieldName) {
|
|
|
|
|
|
|
|
var collection = this;
|
|
|
|
var schema = _.omit(collection.simpleSchema()._schema, fieldName);
|
|
|
|
|
|
|
|
// add field schema to collection schema
|
|
|
|
collection.attachSchema(schema, {replace: true});
|
|
|
|
}
|
|
|
|
|
2015-04-27 09:55:29 +09:00
|
|
|
/**
|
2015-04-28 10:45:00 +09:00
|
|
|
* Global schemas object. Note: not reactive, won't be updated after initialization
|
2015-04-27 09:55:29 +09:00
|
|
|
* @namespace Telescope.schemas
|
|
|
|
*/
|
2015-04-28 11:32:53 +09:00
|
|
|
Telescope.schemas = {};
|