[RUBY] include method

include method

Rails includes is a method that can greatly reduce the number of accesses when retrieving data from multiple related tables.

ruby.rb


@events = @events.includes(:member)

If you give the name of the association to the includes method, it will be associated immediately after the actual query. Issued a query to get model objects in bulk. In the above example: it will issue a query to get the member objects in bulk.

Looking at the issued sql ...

SELECT "staff_members".*FROM "staff_members"
  WHERE "staff_members"."id" IN (1,2,3,4,5)

Such sql is issued. In other words, use the where clause instead of selecting one by one. A convenient method that solves the N + 1 problem by issuing SQL in a batch.

Recommended Posts

include method
How to use the include? method
Java method
to_i method
java (method)
getRequestDispatcher () method
merge method
Map method
Abstract method
initialize method
List method
puts method
Confirm name input using include? method
Java method
Class method
save! method
getParameter method
[Java] method
private method
rails method
[Java] method
Ruby to_s method
Binary search binary search method
Method to search
Factory Method Pattern
Exception switching method
RxSwift method chain
Rails delegate method
Java8 method reference
[Ruby] slice method
[Ruby] end_with? method
[Ruby] Method memorandum
[HTTP method PATCH]
About the method
[Java] forEach method
[Practice] Map method
[Servlet] Basic method
variable and method
Binary search method
Template Method pattern
Template Method Pattern
0-filled (non-zero) method
JavaSilver11 study method
keycloak test-skip method
Factory Method pattern
[Ruby] initialize method
Ruby build method
undefined method `** _ path'error
java8 method reference
[Java] Random method
Ruby accessor method
[Java] split method
ruby map method
Include image in jar file with java static method