Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Properties included in initial data used to create resource are saved and become gettable/settable #121

jsdalton opened this Issue · 2 comments

3 participants


Not sure if bug or feature, but I found this behavior unusual:

var resourceful = require('resourceful');
resourceful.use('couchdb', { database: 'dummy' });

var Creature = resourceful.define('creature', function () {

var cow = new(Creature)({
    diet:      'grass', // not defined in schema
    vertebrate: true
}); (err, cow) {
    if (err) return console.log(err);
    console.log(; // grass = 'corn';
    cow.color = 'purple'; (err, cow) {
        if (err) return console.log(err);
        console.log(; // corn
        console.log(cow.color); // undefined

(I used couchdb but this holds true for memory as well.

In a nutshell, if you set a property in the initial data passed to the constructor (e.g. diet above), it becomes a de-facto part of the resource thereafter -- i.e. it's stored in the database and it's gettable and settable. This is not true for properties set as attributes on the resource directly.

Like I said, if this is just an undocumented feature, then cool. I just found it a bit surprising.

@jsdalton jsdalton referenced this issue from a commit in jsdalton/resourceful
Jim Dalton Issue #121: Prevent attribute from being set as property on resource …
…if property is not defined

I think this was intended.

@indexzero, @bmeck Can one of you confirm?


@pksunkara @jsdalton Yes this is intended. We opted not to throw errors when extra data comes in but throw away data not defined in the schema

@indexzero indexzero closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.