jeanfredrik / meteor-denormalize

Provides simple methods for common denormalization tasks
13 stars 5 forks source link

Please clarify "Integration with SimpleSchema/Collection2"? #2

Closed thearabbit closed 9 years ago

thearabbit commented 9 years ago

In Integration with SimpleSchema/Collection2, you said ...validate you must pass validate: true as an option in the methods.... I don't understand, please example???

jeanfredrik commented 9 years ago

I've updated README.md with an example. Hope that's enough!

Say we have the following schema for our Posts collection:

new SimpleSchema({
    'title': {
        type: String
    },
    'content': {
        type: String
    }
});

And then we run this:

Posts.cacheCount('commentsCount', Comments, 'post_id');

Collection2 would not allow commentsCount to be added to a post since it's not in the schema. Therefore cleaning/validation is bypassed by default. You can prevent this bypass by setting validate: true, like this:

Posts.cacheCount('commentsCount', Comments, 'post_id', {validate: true});

But then you'd also have to add commentsCount to the schema:

new SimpleSchema({
    'title': {
        type: String
    },
    'content': {
        type: String
    },
    'commentsCount': {
        type: Number
    }
});
thearabbit commented 9 years ago

Very thanks, I will try.