Friday, November 17, 2006

ActiveRecord (criminal) gotcha

My foray into ActiveRecord started with this simple bit of code:
require 'active_record'

class Message < ActiveRecord::Base

  establish_connection(:adapter => "oci",
  :username => "someuser",
  :password => "somepasswd",
  :host => "somehost")

  set_table_name "MESSAGE"
  set_primary_key "MESSAGE_ID"
  set_sequence_name "SEQ_MESSAGE"


msg = => "Test message")
Very straightforward, no reason why it shouldn't work, but it didn't: Oracle kept complaining that I was supplying the MESSAGE_ID column twice. No amount of tweaking, googling and tearing out my hair got me anywhere, and I lost nearly a whole day because of this. Finally, out of sheer desperation, I changed "MESSAGE_ID" to lower case.


(I'm not even going to ask why upper case table names are OK, while upper case column names are not)