#918 ✓resolved
ash.gti

BigDecimal and queries in dm-core/next

Reported by ash.gti | June 22nd, 2009 @ 03:46 PM | in 0.10.0

I am using the current dm-core/next (I did rake install after I checked it out) and I have noticed an issue with BigDecimal not working in the queries.

Doing something like:

Model.all(:miles => 50.5) always returns [] and no query shows up in the logs.

Model.all(:conditions => ["miles = ?", 50.5]) returns an object and has a query in the log

here is a gist that demonstrates what I am talking about:

http://gist.github.com/133277

Comments and changes to this ticket

  • Dirkjan Bussink

    Dirkjan Bussink June 22nd, 2009 @ 03:49 PM

    • Assigned user set to “Dan Kubb (dkubb)”

    Dan, what do you think of a change like the following. Imho validity should consider a typecast that will be done in the future when assigning the value. Otherwise this issue will probably also crop up for other types.

    diff --git a/lib/dm-core/property.rb b/lib/dm-core/property.rb
    index f600851..f152d57 100644
    --- a/lib/dm-core/property.rb +++ b/lib/dm-core/property.rb @@ -757,7 +757,7 @@ module DataMapper

     #
     # @api semipulic
     def valid?(value)
    
    • value.kind_of?(primitive) || (value.nil? && nullable?)
    • typecast(value).kind_of?(primitive) || (value.nil? && nullable?) end

      # Returns a concise string representation of the property instance.

  • Dirkjan Bussink

    Dirkjan Bussink June 22nd, 2009 @ 03:49 PM

    diff --git a/lib/dm-core/property.rb b/lib/dm-core/property.rb
    index f600851..f152d57 100644
    --- a/lib/dm-core/property.rb
    +++ b/lib/dm-core/property.rb
    @@ -757,7 +757,7 @@ module DataMapper
         #
         # @api semipulic
         def valid?(value)
    -      value.kind_of?(primitive) || (value.nil? && nullable?)
    +      typecast(value).kind_of?(primitive) || (value.nil? && nullable?)
         end
     
         # Returns a concise string representation of the property instance.
    
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 22nd, 2009 @ 06:05 PM

    • State changed from “new” to “accepted”

    @Dirkjan: Actually, I was thinking of typecasting the value at the point where it is assigned to the AbstractComparison object.

    Before this though, I want to get a patch in that specs the typecasting for each of the primitives.

  • Dirkjan Bussink

    Dirkjan Bussink June 23rd, 2009 @ 12:02 AM

    Ah, yeah, typecasting it there probably makes more sense. I agree on extending the typecasting for primitives indeed, they need to be thoroughly improved.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 23rd, 2009 @ 12:34 AM

    • State changed from “accepted” to “resolved”

    (from [e48baef0e79aad54c96f5e2a73c5d196eefe8326]) Updated Query conditions to typecast values

    [#917 state:resolved] [#918 state:resolved] http://github.com/datamapper/dm-core/commit/e48baef0e79aad54c96f5e2...

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 »

Referenced by

Pages