flatiron/resourceful — Issue #19: Error when saving Creature in example code
Author: richmarr
Created: 2011-11-17 20:08:51+00:00
State: open

Just pulled the latest changes to upgrade to `0.1.3` and bumped into the following error when trying to save the document.

TypeError: Cannot call method 'apply' of undefined
at /Users/richardmarr/local/node/lib/node_modules/resourceful/lib/resourceful/resource.js:159:29
at loop (/Users/richardmarr/local/node/lib/node_modules/resourceful/lib/resourceful/resource.js:51:9)
at Function.runBeforeHooks (/Users/richardmarr/local/node/lib/node_modules/resourceful/lib/resourceful/resource.js:53:6)
at Function._request (/Users/richardmarr/local/node/lib/node_modules/resourceful/lib/resourceful/resource.js:105:8)
at Function.save (/Users/richardmarr/local/node/lib/node_modules/resourceful/lib/resourceful/resource.js:225:15)
at Factory.save (/Users/richardmarr/local/node/lib/node_modules/resourceful/lib/resourceful/resource.js:533:22)
at Object. (/Users/richardmarr/Projects/celeri.ac/web-app/dbtest.js:47:6)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)

Code used:

var resourceful = require('resourceful');

resourceful.use('couchelastic',{
host:'localhost',
port:5984,
cache:false,
database:'test'
});
var Creature = resourceful.define('creature');
Creature.property('diet'); // Defaults to String
Creature.property('vertebrate', Boolean)
Creature.property('belly', Array);

Creature.prototype.feed = function (food) {
this.belly.push(food);
};

var wolf = new(Creature)({
diet: 'carnivor',
vertebrate: true
});
wolf.feed('squirrel');
wolf.save()

Changing this line (resource.js:159)...

that.connection.[method].apply(that.connection, args);

...to the line below seems to fix the problem, but I'm guessing it's not what was intended:

that.connection.connection[method].apply(that.connection.connection, args);