我在用
MongoId 5.4
导轨 4.2
想要执行连接操作并根据条件检索结果。
乐队表
has_many :band_histories, dependent: :destroy
field :name, type: String
field :description, type: String
乐队历史
belongs_to :band, foreign_key: :band_id
field :subject, type: String
field :status, type: String
我想在乐队历史上添加搜索,其中乐队名称为“明星乐队”
普通查询可以像
BandHistory.where(: band_id.in => Band.where(name: 'Star band').pluck(:id))
尝试使用包含使其更通用
BandHistory.includes(:band).where('bands.name':'Star band').count
上面的 include 和 where 子句没有返回任何结果
谁能帮助我做错了什么