1
votes

I'm looking for a tip. I got a Waterline model, which have to be "scanned" by a controller to perform an operation depending on each attribute's properties.

Let me show you

attributes: {
    bar: {
        model: "Baz",
        MyCustomModule: {// should be ignored by Anchor's validation
            foo: false
        }
    },
    bar: {
        type: "string",
        unique: true,
        MyCustomModule: {// should be ignored by Anchor's validation
            foo: true
        }
    }
}

The property MyCustomModule triggers an error, not at my app's startup, but at the first request made to that model.

/some/path/node_modules/sails/node_module/anchor/lib/match/matchRule.js:37
throw new Error('Unknown rule: ' + ruleName);
^
Error: Unknown rule: MyCustomModule
at Object.matchRule (/some/path/node_modules/sails/node_modules/anchor/lib/match/matchRule.js:37:11)
at Anchor.to (/some/path/node_modules/sails/node_modules/anchor/index.js:76:45)
at /some/path/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:188:31
....

Where this problem is really weird, it's because this method works perfectly on my local machine. It only triggers errors on my server, that I've just installed... Is that a configuration problem? Like a "Strict" behavior, or something?

Thanks

Alex

1
It is supposed to trigger an error because the rule isn't recognized. You need to add that custom rule before you can use it. If you want a rule, that is. Else you're just adding MyCustomModule in the wrong place. - galactocalypse
But according to Waterline documentation, Anchor should ignore those rules: link.... I'll try your option - Alexandre Germain
I think that might have something to do with versions then. I have a hunch that the link you attached is incomplete. It is mentioned that "you can tell Waterline to ignore certain properties and not run validations for them" but how you "tell Waterline" isn't described. Pretty sure there's some config info missing in that doc. - galactocalypse

1 Answers

1
votes

Wow, @galactocalypse 's anwser worked well! I did:

module.exports = {
    types: {
        MyCustomModule: function(){
            return true
        }
    },
    attributes: {
        bar: {
            model: "Baz",
            MyCustomModule: {// should be ignored by Anchor's validation
                foo: false
            }
        },
        bar: {
            type: "string",
            unique: true,
            MyCustomModule: {// should be ignored by Anchor's validation
                foo: true
            }
        }
    }
}

And everything was fine then. Thank you so much, I was looking for that kind of options!