【发布时间】:2012-03-09 21:06:37
【问题描述】:
我有两个相关的模型,例如:
class PartCategory < ActiveRecord::Base
has_many :part_types
scope :engine, where(:name => 'Engine')
end
class PartType < ActiveRecord::Base
belongs_to :part_category
end
我想为 PartType 模型添加一个范围,例如:
scope :engine_parts, lambda { joins(:part_category).engine }
但是当我尝试这样做时,我收到以下错误:
NoMethodError: 未定义的方法 `default_scoped?'对于 ActiveRecord::Base:Class
我在范围方面没有太多经验,所以我可能在这里遗漏了一些基本的东西。有人可以告诉我它是什么。
【问题讨论】:
标签: ruby-on-rails activerecord