#1369 suggestion
Kevin Watt

String, :length => 3..100 isn't requiring that the string is not blank

Reported by Kevin Watt | July 19th, 2010 @ 04:21 PM

unless of course you add :required => true to it.

require 'dm-core'
require 'dm-validations'
DataMapper::Logger.new($stdout, :debug)

A MySQL connection:

DataMapper.setup(:default, 'mysql://localhost/ap')

class User
include DataMapper::Resource
property :id, Serial property :name, String, :length => 3..20 end

class Topic
include DataMapper::Resource
property :id, Serial property :subject, String, :length => 3..20 #, :required => true belongs_to :user end

DataMapper.finalize

t = Topic.new 'user' => User.first
t.valid?
puts t.errors.to_hash

-> says its valid, when it shouldn't be.

Comments and changes to this ticket

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) October 31st, 2010 @ 12:20 PM

    • State changed from “new” to “suggestion”

    I believe this is by design. It is a way to express that the field must adhere to the length constraints in case it is not NULL. It could be argued that :length => (3..10) could establish a presence validation itself, because it's probably more likely that you don't want NULL values in that case, but I'm not entirely sure.

  • Piotr Solnica (solnic)

    Piotr Solnica (solnic) May 17th, 2011 @ 02:22 AM

    • Tag set to dm-validations

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages