The blog has moved to http://jessehouse.com/ ... Many google searches point here so I am leaving it operational, but there will be no new posts.
Saturday, April 25, 2009
Strange behavior with Rails find_or_initialize_by_id and Postgresql
The following code sample worked as I would expect when using MySql database - when the :widget_id is 0 it creates a new record with an id of 1; but after switching to Postgresql it was inserting a record into the database with an id of 0 (zero)?
Note: params[:widget_id] does have a value of 0 (zero) when I want to generate a new record vs an actual value when doing an edit. This is a non-standard rails form, I did not experience any issues with a standard new/create view/action scenario.