title: How to add less or equal to condition (`<=`) on rails active record association to select only certain data?
body: <p>In general, my report shows Masters. But I need to display only one wizard for this algorithm. </p>
  
  <p>This request displays several wizards on a selected date for a report. </p>
  
  <pre><code>  def get_masters_name
      str = ''
      team.masters.each do |m|
        str += "#{m.full_name}"
      end
      return str
    end
  </code></pre>
  
  <p>And I need to display only one master in the report if his start date will be less (but approximately equal) or equal to the date of the report.</p>
  
  <p>This is approximately what this query would look like in SQL:</p>
  
  <pre><code>SELECT * FROM * WHERE team.team_id and report_date = (SELECT MAX(master.date_work) FROM master WHERE master.date_work &lt;= report_date)
  </code></pre>
  
  <p>report.model:</p>
  
  <pre><code>class Report &lt; ActiveRecord::Base
    self.table_name = 'reports'
    belongs_to :team, foreign_key: 'teams_id'
  
    def get_masters_name
      str = ''
      team.masters.each do |m|
        str += "#{m.full_name}"
      end
      return str
    end
  end
  </code></pre>