Discover a library that offers the ability to link helpers to collections in this manner:
Meteor.users.helpers({
profile: function() {
return Profiles.findOne(this.profileId);
}
});
This method works well for established collections, but my goal is to create "general" helpers that are automatically applied to every single collection in my database.
EveryCollection.helpers({
fullName: function() {
var schema = this.simpleSchema()._schema;
if(hasKey(schema, 'firstName') && hasKey(schema, 'lastName')) {
return getKey(this, 'firstName') + " " + getKey(this, 'lastName');
}
}
});
With this in place, I could use it like this:
> Admins.findOne().fullName();
"Cat Woman"
> Meteor.users.findOne().fullName();
"Bat Man"
This helper would be added by default to every collection. Is it feasible? It seems like it may involve modifying the prototype
, but I am uncertain about where exactly to add it.
EDIT: The example provided was not ideal, looking for something that functions on an instance variable