&tag(ActiveRecord); *目次 [#t9585ef4] #contents *参考情報 [#xd595ebe] -[[読書メモ+tips+日記:[Ruby] ActiveRecord を単体で(Railsアプリの外で)使う:http://blog.livedoor.jp/takaaki_bb/archives/50602246.html]] -[[ActiveRecord を 単独で使う例: katoy: cocolog:http://youichi-kato.cocolog-nifty.com/blog/2008/06/activerecord_0c49.html]] *Tips [#za8f7a18] **複数のデータベースに接続する [#jdc8bc0c] -ActiveRecord::Baseを継承したクラスでestablish_connectionをそれぞれ設定する。 #pre{{ class OldPerson < ActiveRecord::Base self.table_name = 'person' self.inheritance_column = :old_type self.establish_connection(:adapter=>"mysql2",:host=>"localhost",:username=>$dbuser,:password=>$dbpasswd,:data\ base=>$olddbname) end class Person < ActiveRecord::Base self.inheritance_column = :old_type self.establish_connection(:adapter=>"mysql2",:host=>"localhost",:username=>$dbuser,:password=>$dbpasswd,:data\ base=>$newdbname) end }} **type列がエラーになる [#k2b54f44] -self.inheritance_column = :old_typeのようにして回避する #pre{{ class OldPerson < ActiveRecord::Base self.table_name = 'person' self.inheritance_column = :old_type end }}