After reading a bit about models in [David Weldon’s blog][1] I see sense in using this kind of convention. My only problem is implementation. I cannot get this to work even for the simplest of collections.
I have this:
var region = {
canInsert: function () {
return false;
}
};
Regions = new Mongo.Collection("regions", {
transform: function (doc) {
var newInstance = Object.create(region);
return _.extend(newInstance, doc);
}
});
KM.Schemas = KM.Schemas || {};
KM.Schemas.regionSchema = new SimpleSchema({
regionTitle: {
type: String,
label: "Region",
max: 100
},
regionCode: {
type: String,
label: "Region Code",
max: 10
},
focalPoint: {
type: String,
label: "Focal Point",
max: 100
},
contactEmail: {
type: String,
label: "Email",
max: 500,
regEx: SimpleSchema.RegEx.Email
},
"contactEmail.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"contactEmail.$.verified": {
type: Boolean
}
})
Regions.attachSchema(KM.Schemas.regionSchema);
When I test by running console.log(Regions.canInsert); I get undefined. What am I doing wrong?
I would also like to have the same funtionality for Meteor.users where I can simply check user.isSuperAdmin. isSuperAdmin can take an array of roles which might need to be changed at any time hence the need for one function checking for superAdmin.
The canInsert parameter would check user.isSuperAdmin which for now I can’t execute because I haven’t quite wrapped my head around transforms.
Any guidance on these?
[1]: https://dweldon.silvrback.com/models