Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

AR validates_uniqueness_of floats and find_by_FLOAT_FIELD

#1791

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 :-)

Reported by joahking · January 23rd, 2009 @ 12:01 PM

State: invalid
Milestone: 2.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: none

Activity

  1. Ryan Bigg
    Ryan Bigg
    • 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.

    April 10th, 2010 @ 11:42 AM

  2. David Trasbo
    David Trasbo
    • 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.

    April 14th, 2010 @ 08:56 PM

  3. Ryan Bigg
    Ryan Bigg
    • State changed from new to invalid

    April 14th, 2010 @ 09:31 PM