rails中 model里的两个类有继承关系 如何来处理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问答
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值