title: Rails: How should I run my associated objects' callbacks before the parent's callbacks?
body: <p>I have an <code>Invoice</code> model, which <code>has_many :line_items</code>.</p>
  
  <p>Both models have <code>before_validation</code> callbacks. The invoice's callback requires that the line items' callbacks have been run first. However, by default the invoice's callback gets run, then the callback for each line item is run.</p>
  
  <p>Is there a good way ensure that the line items are validated first, then the invoice?</p>
  
  <p>At the moment, I'm toying with something like this:</p>
  
  <pre><code>class Invoice &lt; ActiveRecord::Base
    before_validation :do_something
    ...
  
  private
    def do_something
      line_items.each { |line_item| line_item.run_callbacks(:validation) }
      # Then do whatever I need here - I've forced the callback order
    end
  end
  </code></pre>
  
  <p>Is there a nicer way to handle this?</p>