Strange AR issue

I'm seeing a strange issue with the following code. I've also included the relevant log entries. Note that 'released_on' is set in the SELECT query but is NULL in the INSERT query. What gives?

year = hash["release_date"] || hash["year"] album = Album.find_or_create_by_title_and_released_on :title => hash["album"], :number_of_tracks => hash["track_count"], :released_on => year

  Album Load (0.2ms) SELECT `albums`.* FROM `albums` WHERE (`albums`.`released_on` = '1978') AND (`albums`.`title` = 'Drum Outtakes') LIMIT 1

  AREL (2.1ms) INSERT INTO `albums` (`created_at`, `released_on`, `updated_at`, `title`, `number_of_tracks`) VALUES ('2011-01-03 22:43:27', NULL, '2011-01-03 22:43:27', 'Drum Outtakes', 23) M

What column type is released_on?

Colin

released_on is of column type DATE.

released_on is of column type DATE.

Please don't top post, insert your comment into the previous email. It makes it easier to follow the thread. Thanks

Looking at your post it seems that you are passing '1978'. You may know that that is a date but I wonder whether rails does. It might be worth trying passing a Date in to find_or_create_by.

Colin

Sorry about the top posting. I know better, but I'm using the Google Groups web interface, so I spaced on that.

Anyway, you are correct about Rails needing to know that '1978' is a date. Changing the following code:

year = hash["release_date"] || hash["year"]

to:

year = hash["release_date"] || Date.new(hash["year"].to_i)

worked.

Thanks!