title: Ruby on Rails - Active Record FIlter where the value of a referenced table is > 0
body: <p>I am currently trying to filter out from selected data in Ruby on Rails those where the attribute &quot;amount_available&quot; is greater than zero. This would be no problem via @events.where(ticket_categories.amount_available &gt; 0), but ticket_categories is an array with not a fixed length, because there can be multiple categories. How can you easily iterate through the array in the where clause and do this comparison?</p>
  <p>I only need the events in the output where at least one associated category has the amount_available &gt; 0.</p>
  <p>This is my code:</p>
  <pre><code>      @upcoming_events = @events.where(&quot;date &gt;=?&quot;, Date.current)
        @available_events = @upcoming_events.where(ticket_categories[0].amount_available &gt; 0)
        json_response(@available_events)
  </code></pre>