【发布时间】:2012-07-21 09:47:25
【问题描述】:
我有 3 个模型
城市.rb
has_many :places
Place.rb
has_many :reviews, as: :reviewable
以及具有我希望能够检查的属性状态的评论。
评论.rb
belongs_to :reviewable, polymorphic: true
state_machine :initial => :draft do #etc.
我希望能够调用 City.find("somecity").places
而不是显示所有地点,而是替换默认范围以仅查找具有“已发布”状态的评论的地点
在 activerecord 中类似于...
City.find("somecity").places.where('reviews.state' => 'published')
有没有办法在 mongoid 中做到这一点,或者我的第二个选择是将新属性合并到每当评论发布时设置为活动的位置。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongoid mongoid3