So I have an existing database that I’m trying to manipulate through ActiveRecord. All of the column, table, and database names are camel-cased, ie. myColumnOne, etc. This doesn’t really pose a problem except that, when I was trying to define the associations between the tables, I can’t get Rails to accept and leave my input for the foreign key names alone.
For example: I’m trying to define an association between a table called cableModems and a table called cmModels, where
cableModem has_one :cmModel, :foreign_key => “cmModelId”
Rails seems to want to say that the foreign_key is actually cm_model_id. Even if I input it the way I showed above.
My question is this: Is there any way to make Rails accept the casing? Or do I need to go about this without the associations?
Many Thanks!
After digging through the Ruby on Rails API docs to trace the execution path for
has_one, it’s quickly become fairly clear that there is no quick and easy way to prevent the automatic de-camelCasing. With named scopes and one or two custom methods, you should be able to replicate the functionality ofhas_onefairly easily, so I would suggest foregoing the association for now, and possibly submit that as a ticket on the Rails Lighthouse.