This seems like it must have been asked before - I really did try to
find it in the archives, so my apologies if it’s already out there.
Utilizing ActiveRecord, I would like to specify a prefix for the
column names in my table. For example, in ‘Recipe 16 Integrating with
Legacy Databases’ (Rails Recipes, from PragProg, by Fowler) they deal
with integration with a WordPress db where all field names are
preceded by “comment_” – i.e. comment_author_email.
The recipe explains how to deal with the primary key (comment_id) via:
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
which is great: the primary key would obviously be the most important
piece to get working
However, it stops short of going into detail on dealing with this on
the other column names.
I guess what I’m looking for is a nice clean way to take their extent
their example - allowing me to reference the non-key fields as
“author_email” instead of needing to always prefix and say things like
“comment_author_email” all over my whole application. and since this
will be in a more complete environment: I also don’t want to remove
“comment_” from the front of every field name in the whole db! It
will need to be specific to the Comment class itself.
Any help is most appreciated. Thanks.