How do I (easily) use a char column as a primary key? (No, I can''t change the database schema - legacy DB, nazi DBAs, you know the drill..) Luckily, the column is named ''id''. Everything seems to work OK except for inserts. Then I''ve got to hack the controller to manually assign the id to record variable: @status_type.id = @params[:status_types][:id] if !@status_type.id The standard method doesn''t seem to assign it: @status_type = StatusType.new(@params[:status_type]) I tried making it an accessible attribute (attr_accessible) but that didn''t seem to work. So now I''ve got a hack that works, but is very nice. This should really be a characteristic set in the model I would think. I tried using before_save; but there I don''t have access to @params in there. I think I remember doing this successfully several months ago, but can''t remember or find it :-(. Is there any way of more elegantly telling Rails that I need to be able to manually set the primary key, and that it shouldn''t assume it''s going to be an auto-increment? Any suggestions? Thanks.
Kian Wright wrote:> How do I (easily) use a char column as a primary key? (No, I can''t change the database schema - > legacy DB, nazi DBAs, you know the drill..) Luckily, the column is named ''id''. Everything seems > to work OK except for inserts. Then I''ve got to hack the controller to manually assign the id to > record variable: > @status_type.id = @params[:status_types][:id] if !@status_type.id > The standard method doesn''t seem to assign it: > @status_type = StatusType.new(@params[:status_type]) > I tried making it an accessible attribute (attr_accessible) but that didn''t seem to work. So now > I''ve got a hack that works, but is very nice. This should really be a characteristic set in the > model I would think. I tried using before_save; but there I don''t have access to @params in there. > > I think I remember doing this successfully several months ago, but can''t remember or find it :-(. > Is there any way of more elegantly telling Rails that I need to be able to manually set the > primary key, and that it shouldn''t assume it''s going to be an auto-increment? Any suggestions? > > Thanks.i have a similar problem. did you find any more on this? -felix