This project is archived and is in readonly mode.

#1791 ✓invalid
joahking

AR validates_uniqueness_of floats and find_by_FLOAT_FIELD

Reported by joahking | January 23rd, 2009 @ 12:01 PM | in 2.x

if you try this:


model WithFloat < ActiveRecord::Base
validates_uniqueness_of :lat
end

right now fails (at least mysql, which is my itch!), mainly because the query AR builds is:


SELECT `with_floats`.* FROM `with_floats` WHERE `with_floats`.`lat` = 49.2123

which fails to find existing floats, read more http://dev.mysql.com/doc/refman/...

I am right now working on it in http://github.com/joahking/rails...

My main itches are:

  • guaranteeing unique validations on floats (100 % done as now!).

NOTE: mysql validations test are passing (100 %), but ALL mysql tests dont! I'll get into that next does not look hard

  • guaranteeing find_by_FLOAT_FIELD works (1 % done).

NOTE: test added that fails

my main goal is to make it for mysql, if other db are not tough I would make them too, but if someone like to help would be cool.

cheers, joahking

PS: the issue reported here is NOT happening with BigDecimals and its mysql Decimal repressentation :-)

Comments and changes to this ticket

  • Ryan Bigg

    Ryan Bigg April 10th, 2010 @ 11:42 AM

    • Assigned user set to “Mikel Lindsaar”

    Any further news on this? I tried today on Rails 2.3.5 and got the following query by doing a Place.find_by_lat

    SELECT * FROM "places" WHERE ("places"."lat" = '45.3243')
    

    To me, this is expected behavior.

  • David Trasbo

    David Trasbo April 14th, 2010 @ 08:56 PM

    • Assigned user changed from “Mikel Lindsaar” to “Ryan Bigg”

    Like Ryan, I was unable to duplicate this issue with Rails 2.3.5:

    ➜  code  rails -v
    Rails 2.3.5
    ➜  code  rails validates_uniqueness_of_float
    ...
    ➜  code  cd validates_uniqueness_of_float 
    ➜  validates_uniqueness_of_float  script/generate model place lat:float
    ...
    ➜  validates_uniqueness_of_float  rake db:migrate
    (in /Users/dtrasbo/code/validates_uniqueness_of_float)
    ...
    ➜  validates_uniqueness_of_float  script/console 
    Loading development environment (Rails 2.3.5)
    ruby-1.8.7-p249 > Place.create!(:lat => '42.123')
     => #<Place id: 1, lat: 42.123, created_at: "2010-04-14 19:53:00", updated_at: "2010-04-14 19:53:00"> 
    ruby-1.8.7-p249 > Place.create!(:lat => '42.123')
    ActiveRecord::RecordInvalid: Validation failed: Lat has already been taken
    ...
    ruby-1.8.7-p249 > Place.find_by_lat(42.123)
     => #<Place id: 1, lat: 42.123, created_at: "2010-04-14 19:53:00", updated_at: "2010-04-14 19:53:00">
    
    class Place < ActiveRecord::Base
      validates_uniqueness_of :lat
    end
    

    This ticket can be closed.

  • Ryan Bigg

    Ryan Bigg April 14th, 2010 @ 09:31 PM

    • State changed from “new” to “invalid”

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages