我有这样一个模型:的Rails + MongoID - 查询的属性
class Lesson
include Mongoid::Document
field :title, :type => String
field :category, :type => String
field :price, :type => Float
field :description, :type => String
field :user_id, :type => String
validates_presence_of :title
validates_presence_of :category
validates_presence_of :price
validates_presence_of :user_id
attr_accessible :title, :category, :description, :price
end
而且我想这样的查询:
@lessons_by_user = Lesson.find_by_user_id current_user.id
而且我越来越:
未定义的方法`find_by_user_id'用于课程:类
如何通过MongoID中的特定属性查询?
我知道如何做到这一点是这样的:
@lessons = Lesson.all(:conditions=>{:user_id=>current_user.id.to_s})
,但我想知道是否有捷径?
太棒了。真的很高兴知道。 – 2012-03-17 06:17:18