title: validate the presence of at least one association object in rails 3.2
body: <p>I've one small problem, I can't get solved. I want to validate that there is at least one associated model. Like in the following</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  has_many :things
  validates_presence_of :things
  end
  
  class Thing &lt; ActiveRecord::Base
  belongs_to :user
  end
  </code></pre>
  
  <p>This works fine when I update my model via <code>#update_attributes</code>, but when I simply set <code>@user.things = []</code>, I am able to get invalid data in the database. My workaroud to solve this is to overwrite the setter method</p>
  
  <pre><code>def things=(val)
    begin
      if val.blank?
        errors.add(:things, "not valid")
        raise SomeError
      end
      super
    rescue SomeError
      false
    end
  end
  </code></pre>
  
  <p>But somehow this doesn't feel right. Isn't there a way to archive the same result via validations and/or callbacks, preferably so that <code>#things=</code> return false (and not <code>val</code>) and so that <code>@user.things</code> is not changed (I mean the cached <code>@user.things</code>, <code>@user.things(true)</code> should work fine anyway).</p>