我正在寻找一种在 Rails 中检查数据库模式和自动生成模型的方法。有谁知道这样做的项目/宝石?
Active Record对此有好处。如果你想在导轨外使用它,那么
class Foo < ActiveRecord::Base
# In case the table name not following rails convention
self.table_name = 'bar'
end
db_config = {
adapter: 'mysql2',
host: 'localhost',
port: 3306,
database: 'foobar'
}
ActiveRecord::Base.establish_connection(db_config)
就这样。