1

I am using

  • MongoId 5.4

  • Rails 4.2

Want to perform join operation and retrieve the result based on criteria.

Band Table

    has_many :band_histories, dependent: :destroy
    field :name, type: String
    field :description, type: String

Band History

   belongs_to :band, foreign_key: :band_id
   field :subject, type: String
   field :status, type: String

I want to add make a search on Band history where band name is 'Star band'

Normal Query Can be Made like

BandHistory.where(: band_id.in => Band.where(name: 'Star band').pluck(:id))

Trying to use includes to make it more generic

BandHistory.includes(:band).where('bands.name':'Star band').count

Above include and where clause is not returning any result

Can anyone help where i am doing wrong

Kunal Vashist
  • 2,380
  • 6
  • 30
  • 59

0 Answers0