Ruby On Rails ActiveRecord SQL 视图到架构中
我创建了一个视图,并通过使用执行 sql 的迁移创建视图,能够通过 Rails 成功访问它。
这样做的问题是视图没有输入到架构中。因此,当我需要创建测试数据库来针对视图运行测试时,不会创建视图。然后我需要通过运行 sql 语句来创建它。有没有办法在 ruby on Rails 中优雅地实现 SQL 视图?
我的环境: Ruby on Rails 3.0.3 PostgreSQL 8.3
I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql.
The problem with this is that the view is not entered into the schema. So when I need to create my test database to run my tests against the view is not created. I then need to create it by running the sql statement. Is there a way to implement SQL views elegantly in ruby on rails?
My environment:
Ruby on Rails 3.0.3
PostgreSQL 8.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
rails_sql_views gem 旨在解决这个问题。它增加了对模式转储器的支持以包含视图,这意味着您可以在测试数据库中使用它们。我不确定它在 Rails 3 中的表现如何,但 github 问题列表中有一个拉取请求,似乎添加了 Rails 3 支持。
The rails_sql_views gem is intended to solve this problem. It adds support to the schema dumper to include views, which means you can use them in your test database. I'm not sure how well it works in Rails 3, but the github issues list has a pull request that appears to add Rails 3 support.
可能吧。使用 config.active_record.schema_format = :sql 可能会有所帮助。
Possibly. using
config.active_record.schema_format = :sql
may help.