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.
我有一个预先存在的MySQL数据库,其命名约定远非Rails约定。除了手动制作每个模型之外,是否有任何选项可以为Rails准备好所有数据库信息?显然,脚手架在这里不会有任何好处。
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.
PS-只是为了澄清,我坚持使用数据库结构。我只需要给Rails提供与MySQL数据库交互的必要信息。
1 个解决方案
#1
1
You can use
您可以使用
set_table_name :name
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
belongs_to:other_model,:foreign_key =>:column_name,:primary_key =>:column_name
to force the relationship ids
强迫关系ids
(gets REALLY annoying, but if you must)
(真的很烦人,但如果你必须的话)
#1
1
You can use
您可以使用
set_table_name :name
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
belongs_to:other_model,:foreign_key =>:column_name,:primary_key =>:column_name
to force the relationship ids
强迫关系ids
(gets REALLY annoying, but if you must)
(真的很烦人,但如果你必须的话)