2012-11-07 90 views
1

我使用PosgreSQL适配器连接到数据库Vertica的其中大部分是兼容PostgreSQL的,但不支持像client_min_messages选项(目前仍在传递给PGconn.connect尽管database.yml不存在)数据库适配器。我做了一个快速和肮脏的猴子补丁ActiveRecord::ConnectionAdapters::PostgreSQLAdapter但问题是,我想一切都在AR在延迟加载和原始文件被我的补丁后读取。猴修补的Rails应用程序

如果我在猴子补丁的顶部添加require 'active_record/connection_adapters/postgresql_adapter'然后ActiveRecord的尝试建立连接和失败。是否有可能改变这种行为,使猴子补丁工作,或者我应该只写一个完整的连接适配器?

+0

你已经完全模块,您来做到这一点? – wuntee

回答

4

你可以连接你的代码railties初始化。从我的宝石multi_config包括样品:

module <YourModule> 
    # Railtie subclass for the gem/plugin 
    class Railtie < Rails::Railtie 

    # Railtie initializer method 
    initializer '<your_plugin>.active_record' do 

     # When active_record is loaded, only then run this. 
     ActiveSupport.on_load :active_record do 
     # Hook your code here. For .e.g. 
     ActiveRecord::Base.send(:include, <YourPluginModule>) 
     end 
    end 
    end 
end 
+0

谢谢,工作完美 – synapse