2

Suppose search_array = [1, 3, 6] and Model has_and_belongs_to_many ChildModels

I want to return Models which have as HABTM link to all of the ChildModels in search_array.

My code, for those that asked

# Find drivers where driver has ALL OF the availables in the array
chunk = start
block_ids = []
while chunk <= ending
  block_ids << Block.where(hour: chunk.hour, day: chunk.wday).take.id
  chunk += 1.hour
end
drivers = drivers.where( availables: block_ids ) # This line is the issue

Currently, the code will find drivers where the driver has ANY OF the availables in the array block_ids

Will Taylor
  • 1,994
  • 2
  • 23
  • 36
  • After reading the [documentation](http://guides.rubyonrails.org/active_record_querying.html) about querying ActiveRecord objects, where are you stuck? Please show the code you have written yet and describe what your exact problems are. – Holger Just Apr 14 '15 at 16:31
  • Code included above. – Will Taylor Apr 14 '15 at 16:45

0 Answers0