Skip to content

Instantly share code, notes, and snippets.

@pegli
pegli / gist:5951901
Last active December 19, 2015 11:59
prototype methods for attachment management
module.exports.afterModelCreate = function(Model) {
Model = Model || {};
Model.prototype.idAttribute = '_id'; // true for all TouchDB documents
Model.prototype.config.Model = Model; // needed for fetch operations to initialize the collection from persistent store
Model.prototype.attachmentNamed = function(name) {
var doc = db.documentWithID(this.id);
if (doc) {
return doc.currentRevision.attachmentNamed(name);