我是 mongoid 的新手,我在查询数据库的内部关系时遇到问题:
这是我希望为其创建查询的第一个模型
class User
include Mongoid::Document
include Mongoid::MultiParameterAttributes
include Geocoder::Model::Mongoid
has_many :hosted_meals, class_name:'Meal', inverse_of: :host
has_and_belongs_to_many :followers, class_name: 'User', inverse_of: :following
.
.
.
end
第二个模型
class Meal
include Mongoid::Document
include Mongoid::Timestamps
include Geocoder::Model::Mongoid
field :privacy, type: String, default: 'p'
belongs_to :host, class_name: 'User', inverse_of: :hosted_meals
我试图创建一个执行以下操作的 mongo 查询:
返回所有类型为“p”的餐点
返回所有餐点的类型为“f”,并且它们的主人在当前用户的关注者中,如下所示:
Meal.where(:privacy => 'f', :host_id.in => )