我是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 =>)