I have a new project going on with an existing website and a mysql backend. Now, the website as it is right now is written in php (no framework, ouch) and the mysql tables do not follow any conventions. For example, table names are not always plural, the unique identifier per table is not always called id
but something like c_id
, sometimes there are no timestamp fields for created_at and updated_at, and if there are, they have a different name.
Now I want to build an admin panel for the website in Rails that will access the same database. I have two options:
- Change the database to follow the rails conventions and modify the php app and all queries accordingly
- Somehow tell Rails that it shall treat something like `c_id` as `id`, and singular names as plural names, etc.
Of course, the first option is technically feasible but probably a huge pain. This is why I would definitely prefer the second option and wonder if it is possible for each model to tell Rails how to treat things instead if they don't follow the convention. In my mind this would look something like:
class ModelClass < ActiveRecord::Base
treat :user, as: :users
treat :user.u_id, as: :id
treat :user.created, as: :created_at if exists
treat :user.last_update, as: :updated_at if exists
end
This is just pseudo-code, but you get the idea. Is something like this possible?