我有 3 个模型
城市.rb
has_many :places
地点.rb
has_many :reviews, as: :reviewable
以及具有我希望能够检查的属性状态的评论。
评论.rb
belongs_to :reviewable, polymorphic: true
state_machine :initial => :draft do #etc.
我希望能够调用 City.find("somecity").places
并且不显示所有地点,而是替换默认范围以仅查找具有“已发布”状态的评论的地点
在活动记录中,类似...
City.find("somecity").places.where('reviews.state' => 'published')
有没有办法在 mongoid 中做到这一点,或者我的第二个选择是将一个新属性合并到每当发表评论时设置为活动的位置。