Closed
tj opened this Issue Feb 18, 2012 · 6 comments

Projects

None yet

4 participants

@tj
tj commented Feb 18, 2012

"Nothing special, you will just have to use dirtier syntax, but that's ok." - no one writes their js like that haha dont be dumb

@vadimdemedes
Owner

Thank you for the nice comment. It would be even more useful, if you could tell me your thoughts on how to do this better. I'm not asking about implementation and working code. Just thoughts and ideas. That would be great.

@Zecc
Zecc commented Feb 22, 2012

Well, I guess I will take this opportunity to mention that there must be something wrong with that example, since you are assigning undefined to Post the first time around. Did you forget to " return Post; " ?

@vadimdemedes
Owner

Oh, yeah, totally missed that. Thank you! Will fix.

@vadimdemedes vadimdemedes added a commit that referenced this issue Feb 26, 2012
@vadimdemedes fixed issue #1 fb311d0
@vadimdemedes
Owner

Update pushed.

@weepy
weepy commented Feb 26, 2012

maybe something like :

var Mongorito = require('mongorito');

Mongorito.connect('database', ['127.0.0.1:27017'], 'user', 'password');
Mongorito.cache(['127.0.0.1:11211']);

function Post(){ // constructor
   Mongorito.model.call.call(this, 'posts');
}

Post.prototype.validateTitle = function(callback){ // declare methods, like this
        if(! this.title) {
            callback(false);
        } else {
            callback(true);
      }
}

Post = Mongorito.bake(Post); // Now, we are ready to go!

I'd say a better API would be something like:

var Post = Mongorito.model('posts', {
  title: 'defaultTitle'
})

var SpecialPost = Post.extend('posts', {
  title: 'defaultTitle'
})
@vadimdemedes
Owner

@weepy Thank you! I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment