Rails & Pre-existing MySQL Database: Is there an easy way to integrate database structure into Active Record?

StackOverflow https://stackoverflow.com/questions/10221660

Pergunta

I have a pre-existing MySQL database with naming conventions far from Rails conventions. Is there any option, other than manually making each model, to get all the database information ready for Rails? Obviously scaffold won't do any good here.

It seems like something someone might have written a script to automate, but I wouldn't have the first clue where to look. Google didn't turn anything up on quick inspection.

Thanks!

PS- Just to clarify, I'm stuck with the database structure. I just need to give Rails the necessary information to interact with the MySQL database.

Foi útil?

Solução

You can use

set_table_name :name

to make it such that the table name don't match the model class

belongs_to :other_model, :foreign_key => :column_name, :primary_key => :column_name

to force the relationship ids

(gets REALLY annoying, but if you must)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top