pode assim: borrowed_books.where(loans: { closed_at: nil })
fixed