On Jan 4, 11:53 am, Colin Law <[email protected]> wrote:
> On 4 January 2011 16:47, Michael Irwin <[email protected]> wrote:
>
> > 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
>
>
>
>
>
> > On Jan 4, 5:52 am, Colin Law <[email protected]> wrote:
> >> On 3 January 2011 23:49, Michael Irwin <[email protected]> wrote:
>
> >> > 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)
>
> >> What column type is released_on?
>
> >> 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!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to