title: Rails custom validation on has_many association
body: <p>Given the following models:</p>
  
  <p>Business</p>
  
  <pre><code>class Business &lt; ActiveRecord::Base
    ## OWNERS / EMPLOYEES
    has_many :business_users, as: :business, dependent: :destroy
    has_many :users, through: :business_users
    accepts_nested_attributes_for :business_users, allow_destroy: true, reject_if: lambda { |a| a[:user_id].blank? || a[:role].blank? }
  end
  </code></pre>
  
  <p>BusinessUser</p>
  
  <pre><code>class BusinessUser &lt; ActiveRecord::Base
    belongs_to :business, polymorphic: true
    belongs_to :user
  
    enum role: {:owner =&gt; 0, :employee =&gt; 1, :admin =&gt; 2}
  
    validates_presence_of :user
    validates :user, uniqueness: { scope: :business, message: "Each user can only have one role" }
  
  end
  </code></pre>
  
  <p>User</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
    has_many :business_users
    has_many :businesses, through: :business_users, source_type: Business, source: :business
  
  end
  </code></pre>
  
  <p>How can i make sure that each business has at least one business_user with role :owner?</p>