`
yangtao309
  • 浏览: 65017 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

rails中 model里的两个类有继承关系 如何来处理ORM衍射数据库呢?

orm 
阅读更多
详细说明:
 
model类 
class Resource < ActiveRecord::Base;end 
class Operation < Resource ; end 
class Mod < Resource; end 

migrate类 
class CreateResources < ActiveRecord::Migration 
def self.up 
create_table :resources do |t| 
t.string :name , :limit => 32 
t.integer :sortno 
t.boolean :visiabled 
t.text :remark 
t.string :type , :limit => 32 

t.integer :parent_id 
end 
end 
def self.down 
drop_table :resources 
end 
end 

class CreateOperations < ActiveRecord::Migration 
def self.up 
create_table :operations do |t| 
t.string :sn , :limit => 32 
t.string :icon, :limit => 32 
t.string :tip, :limit => 32 
t.boolean :show_text 
t.boolean :admin_op 

end 
end 

def self.down 
drop_table :operations 
end 
end 

class CreateMods < ActiveRecord::Migration 
def self.up 
create_table :mods do |t| 
t.text :link, :limit => 500 
t.string :type , :limit => 32 
t.text :icon, :limit => 500 

end 
end 

def self.down 
drop_table :mods 
end 
end 


原先rake的时候 生成的Operation 和Mod 都是继承自ActiveRecord::Migration
后来我要求这两个类必须继承Resource 的一些属性(在数据库中没有相应的字段衍射)
如何来设置呢? 我开始考虑过用-糅和(Mix-in) 与多重继承来实现,但是后面的ActiveRecord::Migration
是个实体类并不是模块~ 急 麻烦啊~ 希望各位有想法的可以提议一下~ 或者是更好的解决方案,多谢了
具体回答可以见http://www.iteye.com/problems/433问答
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics