1
我有一個類:爲什麼ARel查詢返回爲ActiveRecord :: Relation類而不是父類?
class Technician < ActiveRecord::Base
scope :named, lambda {|name| where(["first_name LIKE ?", "%#{name}%"])}
end
在軌控制檯,當我做下面的查詢:
technician = Technician.named("john")
technician.class => ActiveRecord::Relation and not Technician
這很重要,因爲我得到一個無方法錯誤,當我嘗試訪問類的屬性:
technician.id => no method error
我做錯了什麼?
錢德拉...感謝您的幫助。這本身會讓我永遠想到這個細微差別。 – 2010-11-20 21:20:39