{"id":1017,"date":"2014-07-06T17:42:20","date_gmt":"2014-07-06T12:12:20","guid":{"rendered":"http:\/\/www.allerin.com\/blog\/?p=1017"},"modified":"2016-05-12T14:49:23","modified_gmt":"2016-05-12T09:19:23","slug":"eager-loading-inwith-rails","status":"publish","type":"post","link":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/","title":{"rendered":"Eager loading in Rails (Ruby on Rails)"},"content":{"rendered":"<p><strong>Eager loading<\/strong> is a way to find objects of a certain class and a number of named associations.<br \/>\nHere I share my thoughts on using it with Rails.<\/p>\n<p><strong>What are N + 1 queries?<\/strong><\/p>\n<div>\n<p>It mainly occurs when you load the bunch of objects and then for each object you make one more query to find associated object.<\/p>\n<p><strong>N + 1 queries problem<\/strong><\/p>\n<p><span style=\"text-decoration: underline;\">Consider below schema:<\/span><\/p>\n<pre>Class User &lt;&lt; ActiveRecord::Base\r\n   has_many :addresses\r\nend\r\nClass Address &lt;&lt; ActiveRecord::Base\r\n   belongs_to :user\r\nend<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\">Consider below example for lazy load:<\/span><\/p>\n<pre>User.all.each do |user|\r\n   puts \u201cName : #{user.name}\u201d\r\nuser.addresses.each_with_index do |add, index|\r\n   puts \u201cAddress #{index + 1} : #{address.address_line_1}\u201d\r\nend\r\nend\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Suppose there is only 10 user and each has 3 addresses then in above example<\/p>\n<p>1 query will be fired to find out users.<\/p>\n<p>i.e. SELECT &#8220;users&#8221;.* FROM &#8220;users&#8221;<\/p>\n<p>And 3 queries to find addresses for each user.<\/p>\n<p>i.e. SELECT \u201caddresses\u201d.* FROM \u201caddresses\u201d WHERE \u201cuser_id\u201d = {user_id}<\/p>\n<p>So in above overall 31 queries will be fire 1 to fetch user records and others to fetch records from addresses i.e.<\/p>\n<pre>30 (N) which makes N + 1 queries.<\/pre>\n<p>&nbsp;<\/p>\n<p>Above can be optimized by using includes or joins.<\/p>\n<p><strong>Using includes<\/strong><\/p>\n<pre>User.includes(:addresses)<\/pre>\n<p>Above 1, query is required to fetch the records from users table.<\/p>\n<p>i.e. SELECT &#8220;users&#8221;.* FROM &#8220;users&#8221;<\/p>\n<p>After loading the users, find will collect the user_id from each one and load all the referenced addresses with one query. Doing so will cut down the number of queries from 31 to 2.<\/p>\n<p>i.e. SELECT &#8220;addresses&#8221;.* FROM &#8220;addresses&#8221; WHERE &#8220;addresses&#8221;.&#8221;user_id&#8221; IN (1, 2, 3 , 4, 5, 6, 7, 8, 9, 10)<\/p>\n<p><strong>Using Joins<\/strong><\/p>\n<p>User.joins(:addresses)<\/p>\n<p>Above will generate below response<\/p>\n<p>SELECT users.* FROM \u2018users\u2019 INNER JOIN \u2018addresses\u2019 ON users.id = addresses.user_id<\/p>\n<p>Above will further reduce the query to 1.<\/p>\n<p><em><span style=\"text-decoration: underline;\">Note:<\/span> Above will remove the user records which do not have associated address records due to inner join.<\/em><\/p>\n<p>So for above we need to modify the join to left join as<\/p>\n<pre>User.joins(\u2018LEFT JOIN addresses ON addresses.user_id = users.id\u2019)<\/pre>\n<p>Above will also returns the multiple objects for the same user if there will be more than 1 records for address for the user, so following modification will be required.<\/p>\n<pre>User.joins(\u2018LEFT JOIN addresses ON addresses.user_id = users.id\u2019).select(\u2018DISTINCT users.*\u2019)<\/pre>\n<p>Also if you wants to use above records for update, then you needs to set read-only(false) like<\/p>\n<pre>User.joins(\u2018addresses\u2018).readonly(false)<\/pre>\n<p>We can also eagerload the polymorphic records.<\/p>\n<p><span style=\"text-decoration: underline;\">Consider the following example.<\/span><\/p>\n<pre>User\r\n   has_many :addresses, :as =&gt; :resource\r\nClient\r\n   has_many :addresses, :as =&gt; :resource\r\nAddress\r\n   belongs_to :resource, :polymorphic =&gt; true\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Eager load for users &amp; clients can be simply done as<\/p>\n<pre>User.includes(:addresses)\r\n   SELECT users.* FROM users\r\n   SELECT addresses.* FROM addresses where addresses.resource_type = \u2018USER\u2019 and addresses.resource_id IN (1,2, 5\u2026user_ids)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Same will be for clients<\/p>\n<p>Here we can eager load for address also.<\/p>\n<pre>Address.includes(:resource)\r\n   SELECT addresses.* FROM addresses\r\n   SELECT users.* FROM users WHERE users. id IN (1,2,5 \u2026resource_id of addresses where resource_type is \u2018User\u2019)\r\n   SELECT clients.* FROM clients WHERE clients.id IN (1,2,5 \u2026resource_id of addresses where resource_type is \u2018Client\u2019)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>So 1 query to fetch records from Model class and 1 for each associated polymorphic association.<\/p>\n<p>So here it will be only 1 + 2 = 3 queries<\/p>\n<p>We can also eager loads from Model where we define the associations.<\/p>\n<p><span style=\"text-decoration: underline;\">Consider below example<\/span><\/p>\n<pre>User\r\n   has_many :addresses, -&gt; { includes(:phones)}\r\nAddress\r\n   has_many :phones\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>When here we make a call to the addresses of the user for example<\/p>\n<pre>user.addresses<\/pre>\n<p>&nbsp;<\/p>\n<p>Here, <em>ActiveRecord<\/em> will eager load all the phones associated with the addresses and will resolve the N + 1 queries problem.<\/p>\n<p><strong>Nested Eager Loading<\/strong><\/p>\n<p>Yes, We can also eager load a relation of an object you\u2019re eager loading, such as<\/p>\n<pre>User\r\n   has_many :addresses\r\n   has_many :orders\r\nAddress\r\n   has_many :phones\r\n   has_one :code\r\nPhone\r\n   has_one :service\r\nCode\r\n   has_one :code_type\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>So here we can eager load all the associated records from user with following<\/p>\n<pre>User.includes(:addresses =&gt; {{:phones =&gt; :service}, {:code =&gt; :code_type}}, :orders)<\/pre>\n<p>&nbsp;<\/p>\n<p>Also, it will be very useful when we are sending records with json response, we can send each required objects, consider below example with many associations and methods.<\/p>\n<pre>render :json =&gt; customer.as_json(\r\n  :only =&gt; [:id, :industry_id, :resident],\r\n  :include =&gt; {\r\n    :company =&gt; { :only =&gt; [:id,:company_number] },\r\n    :address =&gt; { :only =&gt;\r\n      [:id, :first_name, :last_name, :phone, :address_line_1, :city, :province, :zip, :country_id]\r\n    },\r\n    :identification_information =&gt; { :only =&gt; [:id, :passport_number]},\r\n    :primary_contact_user =&gt; {\r\n      :only =&gt; [:id, :email],\r\n      :include =&gt; { :address =&gt; { :only =&gt; [:id, :first_name, :last_name, :phone]}},\r\n    :methods =&gt; [:is_primary_account?]\r\n    }\r\n  },\r\n  :methods =&gt; [:super_user_is_primary_contact?]\r\n)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\">output would look like:<\/span><\/p>\n<pre>{\r\n\"customer\":{\r\n  \"id\":10008,\r\n  \"industry_id\":10000,\r\n  \"resident\":false,\r\n  \"super_user_is_primary_contact?\":false,\r\n  \"company\":{\r\n    \"company_number\":\"FS123 Changed\",\r\n    \"id\":10000\r\n  },\r\n  \"address\":{\r\n    \"address_line_1\":\"Street Address Changed\",\r\n    \"city\":\"Jackson Lane\",\r\n    \"country_id\":10054,\r\n    \"first_name\":\"Mylene\",\r\n    \"id\":10029,\r\n    \"last_name\":\"Lynda\",\r\n    \"phone\":\"9876543210\",\r\n    \"province\":\"Account State\",\r\n    \"zip\":\"12345\"\r\n  },\r\n  \"primary_contact_user\":{\r\n    \"email\":\"costi@kash.com\",\r\n    \"id\":10259,\r\n    \"is_primary_account?\":false,\r\n      \"address\":{\r\n        \"first_name\":\"Raju\",\r\n        \"id\":10533,\r\n        \"last_name\":\"Varma\",\r\n        \"phone\":\"98744113212\"\r\n      }\r\n  }\r\n},\r\n\"success\":true,\r\n\"request_id\":11036\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Eager loading is a powerful tool, but it should be used carefully. You do not want to be loading too much information since it can slow your application.<\/p>\n<p>If you ever feel, your rails app is slow one of the first things, you should look for are these N + 1 queries. There\u2019s an awesome gem that helps you out with that &#8211; Bullet. It\u2019ll warn you when you have a N+1 case (you\u2019re loading information without eager loading), and it\u2019ll also warn you when you are eager loading data that it is not going to be used.<\/p>\n<p>Also, if you do not want to think where to use and not use eager load (wants to achieve automatic eager loading), then there is an awesome gem Goldiloader. Here you do not need to specify eager loads. ActiveRecord did not make you think about eager loading, and it just did the &#8220;right&#8221; thing by default with Goldiloader without you to specifying any eager loads.<\/p>\n<p><strong>There are 3 ways to do eager loading in Rails:<\/strong><\/p>\n<p>1. includes<\/p>\n<p>2. preload<\/p>\n<p>3. eager_load<\/p>\n<p><strong>#preload<\/strong> is using separate DB queries to get the data.<\/p>\n<p><strong>#eager_load<\/strong> is using one big query with LEFT JOIN for each eager loaded table.<\/p>\n<p><strong>#includes<\/strong> delegates the job to <em>#preload<\/em> or<em> #eager_load<\/em> depending on the presence or absence of the condition related to one of the preloaded tables.<\/p>\n<p><strong>#eager_load<\/strong><\/p>\n<pre>User.eager_load(:addresses).where(\u2018addresses.country = ?\u2019, \u2018India\u2019)\r\n\r\nUser.includes(:addresses).where(\u2018addresses.country = ?\u2019, \u2018India\u2019)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Above will generate only one query to eager load the data.<\/p>\n<pre>SELECT\r\n\r\n  \"users\".\"id\" AS t0_r0, \"users\".\"name\" AS t0_r1, \"users\".\"email\" AS t0_r2, \"users\".\"created_at\" AS t0_r3, \"users\".\"updated_at\" AS t0_r4,\r\n\r\n  \"addresses\".\"id\" AS t1_r0, \"addresses\".\"user_id\" AS t1_r1, \"addresses\".\"country\" AS t1_r2, \"addresses\".\"street\" AS t1_r3, \"addresses\".\"postal_code\" AS t1_r4, \"addresses\".\"city\" AS t1_r5, \"addresses\".\"created_at\" AS t1_r6, \"addresses\".\"updated_at\" AS t1_r7\r\n\r\nFROM \"users\"\r\n\r\nLEFT OUTER JOIN \"addresses\" ON \"addresses\".\"user_id\" = \"users\".\"id\"\r\n\r\nWHERE (addresses.country = 'India')\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In the above example, Rails detected that the condition in where clause is using columns from preloaded (included) table names. So, <em>#includes delegates the job to #eager_load.<\/em><\/p>\n<p><strong>#preload<\/strong><\/p>\n<p>If you try above using preload, you will get an exception because you have not joined users table with addresses.<\/p>\n<pre>User.preload(:addresses).where(\u2018addresses.country = ?\u2019, \u2018India\u2019)\r\n\r\nSELECT \"users\".* FROM \"users\" WHERE (addresses.country = 'India')\r\n\r\nFail with no such column: addresses.country\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>So above can be achieved by using preload as follows.<\/p>\n<pre>User.preload(:addresses).where(:country =&gt; \u2018India\u2019)\r\n\r\nSELECT \"users\".* FROM \"users\"\r\n\r\nSELECT \"addresses\".* FROM \"addresses\" WHERE \"addresses\".\"country\" = 'India' AND \"addresses\".\"user_id\" IN (1, 2, 3)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Above if we had use includes instead of preload it would have done same thing as above (used separate DB queries to fetch data).<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Eager loading is a way to find objects of a certain class and a number of named associations.<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[3],"tags":[105,10,19],"class_list":["post-1017","post","type-post","status-publish","format-standard","hentry","category-technology","tag-eagerloading","tag-rails","tag-ror"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.5 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Eager loading in Rails (Ruby on Rails)<\/title>\n<meta name=\"description\" content=\"Here we talk about easier methods of eager loading in Rails. These are few methods I learned during my programming career.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Eager loading in Rails (Ruby on Rails)\" \/>\n<meta property=\"og:description\" content=\"Eager loading is a way to find objects of a certain class and a number of named associations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/\" \/>\n<meta property=\"og:site_name\" content=\"Artificial Intelligence, ROBOTICS, AUTOMATION\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/allerintech\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-06T12:12:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-05-12T09:19:23+00:00\" \/>\n<meta name=\"author\" content=\"Nitesh Varma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nitesh Varma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/\"},\"author\":{\"name\":\"Nitesh Varma\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#\\\/schema\\\/person\\\/62051995e859f22af8935f2c15a7f00d\"},\"headline\":\"Eager loading in Rails (Ruby on Rails)\",\"datePublished\":\"2014-07-06T12:12:20+00:00\",\"dateModified\":\"2016-05-12T09:19:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/\"},\"wordCount\":832,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#organization\"},\"keywords\":[\"eagerloading\",\"rails\",\"ror\"],\"articleSection\":[\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/\",\"url\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/\",\"name\":\"Eager loading in Rails (Ruby on Rails)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#website\"},\"datePublished\":\"2014-07-06T12:12:20+00:00\",\"dateModified\":\"2016-05-12T09:19:23+00:00\",\"description\":\"Here we talk about easier methods of eager loading in Rails. These are few methods I learned during my programming career.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/eager-loading-inwith-rails\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Eager loading in Rails (Ruby on Rails)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/\",\"name\":\"Artificial Intelligence, ROBOTICS, AUTOMATION\",\"description\":\"Empowering Futures: Innovating with AI and Machine Learning\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#organization\",\"name\":\"Allerin\",\"url\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/logo-fire.png\",\"contentUrl\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/logo-fire.png\",\"width\":1000,\"height\":1000,\"caption\":\"Allerin\"},\"image\":{\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/allerintech\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/allerintech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/#\\\/schema\\\/person\\\/62051995e859f22af8935f2c15a7f00d\",\"name\":\"Nitesh Varma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b21e15576ea716b8c732b52f63ca14cccbe5d0d086a907d9017b5146f5c7237a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b21e15576ea716b8c732b52f63ca14cccbe5d0d086a907d9017b5146f5c7237a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b21e15576ea716b8c732b52f63ca14cccbe5d0d086a907d9017b5146f5c7237a?s=96&d=mm&r=g\",\"caption\":\"Nitesh Varma\"},\"sameAs\":[\"http:\\\/\\\/www.allerin.com\"],\"url\":\"https:\\\/\\\/www.allerin.com\\\/blog\\\/author\\\/niteshv\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Eager loading in Rails (Ruby on Rails)","description":"Here we talk about easier methods of eager loading in Rails. These are few methods I learned during my programming career.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/","og_locale":"en_US","og_type":"article","og_title":"Eager loading in Rails (Ruby on Rails)","og_description":"Eager loading is a way to find objects of a certain class and a number of named associations.","og_url":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/","og_site_name":"Artificial Intelligence, ROBOTICS, AUTOMATION","article_publisher":"https:\/\/www.facebook.com\/allerintech","article_published_time":"2014-07-06T12:12:20+00:00","article_modified_time":"2016-05-12T09:19:23+00:00","author":"Nitesh Varma","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nitesh Varma","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/#article","isPartOf":{"@id":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/"},"author":{"name":"Nitesh Varma","@id":"https:\/\/www.allerin.com\/blog\/#\/schema\/person\/62051995e859f22af8935f2c15a7f00d"},"headline":"Eager loading in Rails (Ruby on Rails)","datePublished":"2014-07-06T12:12:20+00:00","dateModified":"2016-05-12T09:19:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/"},"wordCount":832,"commentCount":1,"publisher":{"@id":"https:\/\/www.allerin.com\/blog\/#organization"},"keywords":["eagerloading","rails","ror"],"articleSection":["Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/","url":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/","name":"Eager loading in Rails (Ruby on Rails)","isPartOf":{"@id":"https:\/\/www.allerin.com\/blog\/#website"},"datePublished":"2014-07-06T12:12:20+00:00","dateModified":"2016-05-12T09:19:23+00:00","description":"Here we talk about easier methods of eager loading in Rails. These are few methods I learned during my programming career.","breadcrumb":{"@id":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.allerin.com\/blog\/eager-loading-inwith-rails\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.allerin.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Eager loading in Rails (Ruby on Rails)"}]},{"@type":"WebSite","@id":"https:\/\/www.allerin.com\/blog\/#website","url":"https:\/\/www.allerin.com\/blog\/","name":"Artificial Intelligence, ROBOTICS, AUTOMATION","description":"Empowering Futures: Innovating with AI and Machine Learning","publisher":{"@id":"https:\/\/www.allerin.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.allerin.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.allerin.com\/blog\/#organization","name":"Allerin","url":"https:\/\/www.allerin.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.allerin.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.allerin.com\/blog\/wp-content\/uploads\/2016\/06\/logo-fire.png","contentUrl":"https:\/\/www.allerin.com\/blog\/wp-content\/uploads\/2016\/06\/logo-fire.png","width":1000,"height":1000,"caption":"Allerin"},"image":{"@id":"https:\/\/www.allerin.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/allerintech","https:\/\/www.linkedin.com\/company\/allerintech"]},{"@type":"Person","@id":"https:\/\/www.allerin.com\/blog\/#\/schema\/person\/62051995e859f22af8935f2c15a7f00d","name":"Nitesh Varma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b21e15576ea716b8c732b52f63ca14cccbe5d0d086a907d9017b5146f5c7237a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b21e15576ea716b8c732b52f63ca14cccbe5d0d086a907d9017b5146f5c7237a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b21e15576ea716b8c732b52f63ca14cccbe5d0d086a907d9017b5146f5c7237a?s=96&d=mm&r=g","caption":"Nitesh Varma"},"sameAs":["http:\/\/www.allerin.com"],"url":"https:\/\/www.allerin.com\/blog\/author\/niteshv\/"}]}},"_links":{"self":[{"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/posts\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/comments?post=1017"}],"version-history":[{"count":9,"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/posts\/1017\/revisions"}],"predecessor-version":[{"id":1387,"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/posts\/1017\/revisions\/1387"}],"wp:attachment":[{"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/media?parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/categories?post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.allerin.com\/blog\/wp-json\/wp\/v2\/tags?post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}