Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Autovalidations do not respect :allow_blank #18

Open
solnic opened this issue May 17, 2011 · 3 comments
Open

Autovalidations do not respect :allow_blank #18

solnic opened this issue May 17, 2011 · 3 comments

Comments

@solnic
Copy link
Contributor

solnic commented May 17, 2011

I needed to apply the following patch in my project to see correct behavior with, e.g., optional belongs_to relationships, where the property should be allowed to be blank.

https://gist.github.com/769298


Created by Bernerd Schaefer - 2011-01-07 09:56:10 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1469

@emmanuel
Copy link
Member

Maybe fixed here 2ccda08?

Pretty sure this is fixed, whenever that happened...

@emmanuel
Copy link
Member

Actually, maybe not. I'm shutting up now.

@duien
Copy link

duien commented Mar 2, 2012

I didn't realize issues had been moved over here from Lighthouse, so here's an update I just posted over there:

I'm having this same problem, and it's really infuriating.

I have the following model:

class Product
  include DataMapper::Resource
  property :id, Serial
  property :list_price, Decimal

  # more properties, not relevant to problem
end

I want to update that model from a form and not set a list price, so I have params that look something like this:

{ 'product' => { 'list_price' => '' } }

The auto-validations generated for the list_price property have allow_nil: true but not allow_blank: true, meaning that when I update the product with the params above, it's invalid.

Unlike most of the other auto-validations, it seems there's no way to customize numericality, meaning I have to completely disable auto-validations and manually recreate them. I would expect to be able to do something like one of the following:

property :list_price, Decimal, numericality: { allow_blank: true }
property :list_price, Decimal, allow_blank: true

Ideally, though, I shouldn't even have to do that. I think that allow_blank should default to true under the same conditions as allow_nil since otherwise the property can't be updated from a form, which seems like a pretty prime use-case.

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

No branches or pull requests

3 participants