`
up2u0609
  • 浏览: 17397 次
社区版块
存档分类
最新评论

why we use abstract_class in active_record ?

阅读更多
in the sample below:
class BookLib < ActiveRecord::Base
   self.abstract_class = true
end
  since abstract_class is set to true, this model class shifts to be a fade one(no table will be create for it), why we need a fade model in our project? yeah , we do need, it's powerful air in some cases.
  let's assume a situation: we gonna request a batches data of book, the problem is these data were stored into another independent db. so how we touch them in our project.
let's do it like these:
class BookLib < ActiveRecord::Base
   self.abstract_class = true
   establish_connection("db_#{RAILS_ENV}".to_sym)
 
   validates_presence_of :name
end
class BookTag < BookLib; end
class Book < BookLib; end
   in these way, when we gonna CRUD booktag and book , the project will establish connection first.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics