Ruby on Rails - includes in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Includes
- ActiveRecord with includes ensures that all of the specified associations are loaded using the minimum possible number of queries.
- So when querying a table for data with an associated table, both tables are loaded into memory.
- Author.joins(:books).where(books: { bestseller: true } )will load only authors with conditions into memory without loading books.
- Use joins when additional information about nested associations isn't required.