我想用 mongoid 查询,我有以下模型
class Score
include Mongoid::Document
field :value, :type => Integer
belongs_to :user
end
class User
include Mongoid::Document
field :name, :type => String
field :age, :type => Integer
has_many :scores
我想与他们的用户一起查询集合中的所有分数。但是用户对象中应该只有“名称”字段
我会是这样的
Score.find.all.includes(:user).only(:name)
请说出正确的语法