<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ruby Howto Activerecord on developwith — developer tips</title>
    <link>https://developwith.com/tags/ruby-howto-activerecord/</link>
    <description>Recent content in Ruby Howto Activerecord on developwith — developer tips</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <atom:link href="https://developwith.com/tags/ruby-howto-activerecord/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Eager load children in ActiveRecord</title>
      <link>https://developwith.com/how-do-i/ruby/eager-load-children-in-active-record/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/eager-load-children-in-active-record/</guid>
      <description>&lt;p&gt;Sometimes when making queries for objects using activerecord, it makes sense to eager load relationships. Eager loading is the process of retrieving a set of records and collecting the ids in which to do a bulk query to populate the related objects. The act of preloading the relationships makes the queries faster and reduces the amount of queries in your overall result.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s jump to an example to give you an idea how this works. Below is the model relationship we will use:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Size of active record collection</title>
      <link>https://developwith.com/how-do-i/ruby/size-of-active-record-collection/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/size-of-active-record-collection/</guid>
      <description>&lt;p&gt;Getting the size on an activerecord collection can trigger a query or load the objects in memory depending on the method you use. There are 3 different methods:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;count&lt;/em&gt; - Uses sql &lt;code&gt;count&lt;/code&gt; query for getting the size from db&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;length&lt;/em&gt; - Loads the elements of the collection into memory to get the size&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;size&lt;/em&gt; - Hybrid that gets a count from memory if collection is loaded or &lt;code&gt;count&lt;/code&gt; if not&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;In most cases (depending on the application), the preferred method is going to be count for getting counter caches or counts on a set of records in a database.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
