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