开发者

One model - many DB connections in Rails?

(using Ruby on Rails and ActiveRecord)

In short: Is there some way how a model can use different DB schema for each request?

Why I need id: I have a working intranet application w开发者_JAVA技巧orking for one company but I decided I would like to offer it to other companies. The Rails way would be to add company_id to each model and alway use this scope. But making separate DB schema for each company would make much more sense. Is there some standard way how to do it?

thanks!


What would be wrong with having a separate instance of your application for each company?


Adding company_id to all the models is absolutely the way to go. What you're talking about is very difficult to manage in the long haul, and it may be tricky to ensure the correct connection is used to store the correct data.

Although layering in differentiation like that is annoying, it can be done and proven in a fairly short period of time, and after that things will be easier to manage. With named_scope it is not hard to filter using attributes like that.

The simple alternative is to deploy the application more than once, with a different database.yml for each company, where the data is isolated on the application level, not within the application.

It would be easy to do this with Passenger (mod_rails) and a bit of shell scripting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜