【发布时间】:2012-03-17 04:24:06
【问题描述】:
我有一个这样的模型:
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
我得到:
Lesson:Class 的未定义方法 `find_by_user_id'
如何通过 MongoID 中的特定属性进行查询?
我知道该怎么做:
@lessons = Lesson.all(:conditions=>{:user_id=>current_user.id.to_s})
但我想知道是否有捷径...
【问题讨论】:
标签: ruby-on-rails mongodb mongoid