problem with retrieving nil dates from MySQL

I a have a problem with a time- only field in MySQL returning as nil unless it is exactly "00:00:00" (HH:MM:SS) as stored in a 'time' datatype.

I've played around with various date/time formatting actions in the controller, view, and model but I get a variation of the the following error:

  NoMethodError in AlbumsController#show You have a nil object when you didn't expect it!

Note: there are NO null values in the time column - everything has a value.

I'm using Netbeans 6.7 beta, using Ruby ver. 1.8.6 and AR ver. 2.1.0

thanks for any insight

I a have a problem with a time-

only field in MySQL returning as nil unless it is exactly

“00:00:00” (HH:MM:SS) as stored in a ‘time’ datatype.

Maybe there’s a bug in activerecord that translates “00:00:00” time to ruby nil value?

I’ve played around with various date/time formatting actions in the controller, view, and model but I get a variation of the the following error:

If there’s a bug, it’s in activerecord, so extra code in controllers and view will not help. The best tool to start investigating this is invoke your script/console and play with your models from there. Like this:

record.mytime = time

record.save

record.reload

record.mytime

I’m using Netbeans 6.7 beta

It doesn’t matter what text editor or IDE are you using :slight_smile:

Ruby ver. 1.8.6 and AR ver. 2.1.0

First thing that you should always do when you think you find a bug is to try doing the same thing with the newest version of ActiveRecord. If the buggy behavior is still present in that version, try freezing the latest 2-3-stable git branch in your application (it contains bugfixes made after the last 2.3.x stable version).

If the bug is still present, search for it in the issue tracker:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets?q=mysql+time+nil

If you cannot find anything similar (either among open issues or resolved ones) then you have to report it. You can create a new ticket and describe your problem, but the best way is to prove the bug with some code — we call this a failing test case. To do this you have to clone the rails repository from git (if you don’t have it already) and study existing activerecord tests dealing with mysql-to-ruby type conversion. You can start by searching the “activerecord/test/” directory for “bonus_time”, because that is the only time column in the test schema.