Kelly Felkins
2006-Nov-04 01:37 UTC
[Rails] any recommendations for handling a non autoincrement primary key
Hey everyone, I''m working on an application that has a table with a nice natural primary key. Outside of the rails world it would be *the* primary key. I would prefer to use this natural primary key and define associations that use it. I''ve done so but the problem is that my form for entering a record in this table is currently failing. I''ve used ''set_primary_key'' in the model and I guess when you do this that column is no longer considered an attribute. In the activerecord code there is an array called @attributes, and the method that loads this array checks to see if the column is the primary key before adding the column to the array. My current guess is that rails assumes primary keys are not set but rather assigned by the database. The error occurs when using the form helper. The column name is affiliate_id. The model has this declaration: set_primary_key :affiliate_id The new form (originally a scaffold...) has this: <tr><th align="right">Affiliate Id:</th><td><%= text_field ''affiliate'', ''affiliate_id''%></td></tr> Displaying the ''new'' form gives me: undefined method `affiliate_id_before_type_cast'' for #<Affiliate:0xb7394660> Has anyone had success at *setting* a primary key in a form. Thanks, -Kelly -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060820/825db313/attachment-0001.html