title: Rails finding from nested records
body: <p><code>product.rb</code></p>
  <pre><code>  class Product &lt; ApplicationRecord
      has_many :product_items
    end
  </code></pre>
  <p><code>product_item.rb</code></p>
  <pre><code> class ProductItem &lt; ApplicationRecord
      belongs_to :product
      has_many :prices
    end
  </code></pre>
  <p><code>price.rb</code></p>
  <pre><code>class Price &lt; ApplicationRecord
     belongs_to :product_item
  end
  </code></pre>
  <p>Now price table has a column called <code>otc</code>, it stores one-time cost for the product item and product item can have many prices.</p>
  <p>Objective: The product has many product items but I need to find one minimum cost product item(say <code>default_product_item</code>). Need to select product item(along with otc) for a product with minimum otc from price table.</p>
  <p>I am using ruby 3.0.1, rails 6.1.3.2, database, Postgres.</p>