In the association preload code there's this pattern showing up in a couple places:
through_records.first.class.preload_associations(through_records, source)
through_records.compact.each { |through_record| ... }
# works when through_records is [#<User>, #<User>] but fails BAD when through_records is [nil, #<User>]
The through_records array should be compacted before any of this code.
This patch compacts the two main arrays in this module (records and through_records) just once and at the right time. I could contrive a regression test for this but it's an easy fix and shouldn't need to be addressed again. If anyone wants me to add a test just say so.
Existing tests all pass.