Skip to content

Instantly share code, notes, and snippets.

@merlinstardust
Last active April 5, 2016 17:51
Show Gist options
  • Save merlinstardust/b4ee7b735dce56c911b086185b378ba0 to your computer and use it in GitHub Desktop.
Save merlinstardust/b4ee7b735dce56c911b086185b378ba0 to your computer and use it in GitHub Desktop.
Goes through all collections and attaches association helpers to them
var collections = [];
_.each(collections, function (collection) {
var helpers = {};
var fields = window[relation].simpleSchema().objectKeys();
_.each(fields, function (field) {
var key = field.replace(/Id$/, '');
helpers[key] = function () {
var entity = capitalize(key) + 's';
return window[entity].findOne({_id: this[field]});
};
});
window[relation].helpers(helpers);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment