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

Allow saving empty arrays #330

Merged
merged 1 commit into from
Mar 17, 2020
Merged

Allow saving empty arrays #330

merged 1 commit into from
Mar 17, 2020

Conversation

paulcsmith
Copy link
Member

Closes #294

@@ -0,0 +1,30 @@
class Object
def blank_for_validates_required? : Bool
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem boils down to https://github.com/kostya/blank #blank? returning true for arrays and for Bool if it is false.

So what I did was add this new method we can use in validate_required.

But this makes me wonder if we should fork the blank library and just add these in so this behavior is like this for `blank?

The problem is it may be unexpected for users of Rails since Rails false.blank? # true and [].blank? # true. IMO this behavior is confusing and I'd expect those to return false but maybe it's just me!

cc @edwardloveall @jwoertink

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought is that either way I can merge this in for now to fix the linked issue. But would love to figure out if we should just make these changes to blank? directly in a later PR

@paulcsmith paulcsmith merged commit d179a00 into master Mar 17, 2020
@paulcsmith paulcsmith deleted the pcs/294-save-empty-array branch March 17, 2020 00:21
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

Successfully merging this pull request may close these issues.

Can not save empty array
1 participant