Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom defined rule is not called on multiple attributes #9

Closed
gtarcea opened this issue Mar 27, 2015 · 5 comments
Closed

Custom defined rule is not called on multiple attributes #9

gtarcea opened this issue Mar 27, 2015 · 5 comments
Labels

Comments

@gtarcea
Copy link
Contributor

gtarcea commented Mar 27, 2015

When I define a custom rule as follows and use it in multiple spots, the rule is only called for one attribute. Here is my example:

schema.defineRule('mustExist', mustExist, true);

schema.defineSchema('Sample', {
project_id: {
type: 'string',
minLength: 1,
mustExist: 'projects'
},
owner: {
type: 'string',
minLength: 1,
mustExist: 'users'
}
}

In this case the mustExist rule will look up the item in the named table to validate it exists. However, when I run schema.validate, the only rule defined for mustExist, has the value 'users' associated with it. Only one instance of the rule and its arguments are being kept.

I have a pull request I'll be submitting that resolves this issue.

@jmdobry
Copy link
Member

jmdobry commented Mar 27, 2015

Do you also experience this issue when you use validateSync? Or only with validate?

@gtarcea
Copy link
Contributor Author

gtarcea commented Mar 27, 2015

It happens with validate. I ran into an issue with validateSync in that
my async rules were not being called. I assumed this was working as
designed, and started only using validate so my async rules would run.

The issue I described happens with a set of async rules I have (that can
go off and make calls to a database).

Thanks,

Glenn

Jason Dobry mailto:notifications@github.com
March 27, 2015 at 3:11 PM

Do you experience this issue when you use |validateSync|? Or only with
|validate|?


Reply to this email directly or view it on GitHub
#9 (comment).

@jmdobry
Copy link
Member

jmdobry commented Mar 27, 2015

Yeah, the Sync in validateSync stands for "synchronous". It's faster, and the implementation for it is muuuuch simpler, but it doesn't support asynchronous rules. You have to use validate in order to use asynchronous rules. The implementation for validate is much more complex (you've probably seen) because of the need to queue a bunch of different async tasks, and I believe your fix will probably work.

@gtarcea
Copy link
Contributor Author

gtarcea commented Mar 27, 2015

I did see that :-)
After I thought about it, it made a lot of sense that validateSync skipped the async rules. Perhaps that could be added to the documentation?

The fix is working for me so far. If I run into other issues with it I'll fix them and submit another pull request.

jmdobry added a commit that referenced this issue Mar 27, 2015
Resolves issue #9 with same rules with different arguments getting overwritten
@jmdobry jmdobry added the bug label Mar 27, 2015
@jmdobry
Copy link
Member

jmdobry commented Mar 27, 2015

@gtarcea Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants