十二月
14

今天看到 Rails可以有两个以上的数据库吗 以及 Multiple database handling with Rails。他們的作法有點詭異,而且有一個關鍵性的問題,每次 request 每個不相關的頁面也都得連接一次 external database。可是 Rails 要做這件事情應該沒那麼複雜呀?

1. 設定 config

extradb_production:
adapter:     mysql
host:        localhos
username:    root
password:    blabla
database:    extradb_prod

2. 在相關 Model 利用 estabilish_connection 去做連接而外設定

class lala < ActiveRecord::Base
establish_connection :extradb_production
end

然後收工,連跨 DB 的關連性都沒問題。

Link to 一次連接 Multi Database

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg

Tags:

No Responses

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>