Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate active record models from database

I am looking for a tool or a method which can convert my huge old database to active records model definitions ... like reverse engineering ...

like image 233
goutham Avatar asked Feb 24 '23 23:02

goutham


2 Answers

This is less a reverse engineering problem and more a "does your legacy database adhere to the active record conventions" problem. Most do not and from my experience, it's almost easier to do some migration work on the data end to get it in a state such that it does adhere to those conventions. Rails is a very opinionated piece of software, the less you argue with it, the happier you'll be.

My two cents...

like image 136
chris.baglieri Avatar answered Mar 08 '23 00:03

chris.baglieri


Sorry I don't know a tool either. But creating an active record model is really simple as meager showed it. Additionally you may have to describe the table name and the primary key:

class Artikelgruppe < ActiveRecord::Base
  set_table_name "tblArtGrp"
  set_primary_key "ArtGrpID"
end

As my Rails application uses only a small subset of our legacy database I prefer to create views specific to the needs of my application in the database. I have really problems to describe a join over eg 7 models in Rails but it is really easy to create a view for joining 7 tables in the database.

Why do the Rails people still think they are the centrum of the universe? I have a dozen applications written in different languages and the common ground is the database. Imagine I would have to change the database to make Rails happy ...

like image 20
Klaus Avatar answered Mar 07 '23 22:03

Klaus