
belongs_to association does not work using a select tag selector
Reported by bterkuile | June 27th, 2010 @ 06:08 AM
Problem: belongs_to association should allow empty assignment
(:include_blank => true)
Now a is not an integer error is triggered because assigning a
empty string to an integer property remains an empty string.
Environment: Rails beta4, ruby 1.9.2-preview3
My solution:
Add a check for empty assignment in the numeric typecast:
config/initializers/dm-typecast-fix.rb
module DataMapper
class Property
module Typecast
module Numeric
# Match numeric string
#
# @param [#to_str, Numeric] value
# value to typecast
# @param [Symbol] method
# method to typecast with
#
# @return [Numeric]
# number if matched, value if no match
#
# @api private
def typecast_to_numeric(value, method)
if value.respond_to?(:to_str)
return nil if value.to_str.blank?
if value.to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
$1.send(method)
else
value
end
elsif value.respond_to?(method)
value.send(method)
else
value
end
end
end # Numeric
end # Typecast
end # Property end # DataMapper
Comments and changes to this ticket
-
Martin Gamsjaeger (snusnu) June 27th, 2010 @ 02:29 PM
- Assigned user set to Martin Gamsjaeger (snusnu)
- State changed from new to unconfirmed
-
Piotr Solnica (solnic) February 9th, 2011 @ 08:21 AM
- State changed from unconfirmed to duplicate
dup of #1470
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »