现在有一模型: fruits ,
在其数据表中,有一字段 category, 用来区分不同 fruits ,
我们可否可以新建一个模型: apples ,
让其继承 category = 4 的 fruits ?
也就意味着:
Apple.all 等于 Fruit.where(:category => 4)Apple.new 时, Fruit.category 的值会默认为 4
在强大的Ruby面前,这应该如何实现?
我自己补充答案吧:
class Apple < Fruit default_scope { where(category: 4) } end
付费偷看金额在0.1-10元之间
一周热门 更多>