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

Feature: Make validate_schema_types aware of Plugins::Serialization #1085

Closed
odigity opened this issue Oct 2, 2015 · 2 comments
Closed

Feature: Make validate_schema_types aware of Plugins::Serialization #1085

odigity opened this issue Oct 2, 2015 · 2 comments

Comments

@odigity
Copy link

odigity commented Oct 2, 2015

I'm currently using the Serialization plugin to map an array in ruby to a text column as JSON.

I just tried out the validates_schema_types helper, and got an "is not a valid string" error on that column.

Would be convenient if the validates_schema_types would check for the Serialization plugin and skip columns that have been configured with it.

@odigity
Copy link
Author

odigity commented Oct 3, 2015

So, I didn't want to rush into forking and submitting a PR because frankly I don't have much experience digging into code and contributing to large projects... but I took a look at the code for the relevant plugins, and I suspect this might be accomplished with a change to line 184 of sequel/plugins/auto_validations.rb, from:

validates_schema_types(keys, opts[:schema_types]) if model.auto_validate_types?

to:

validates_schema_types(class.responds_to?(:serialization_map) ? keys - class.serialization_map.keys : keys, opts[:schema_types]) if model.auto_validate_types?

(I would write it differently, putting the key-building code on it's own line and saving the results to a local variable, but I figured the most conservative approach would be start with the minimal change and go from there.)

BTW - The only reason I got this far was because of how cleanly the code is written, so thanks!

@jeremyevans
Copy link
Owner

The auto_validations plugin already uses the :from=>:values option to check the underlying values. If you want to use validates_schema_types with the serialization plugin, use the :from=>:values option just as the auto_validations plugin does, so it looks at the serialized value instead of the deserialized value.

Note that as mentioned in the contribution guidelines, GitHub Issues should only be used to report bugs in the library, not for feature requests like this. Please use IRC or the sequel-talk Google Group to request features or ask for help in the future.

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

No branches or pull requests

2 participants