Validation dependent on unsaved parent

I'm having trouble with a validation that depends on an attribute of a
belongs_to parent. If the child is added to an unsaved parent
(parent.children << new child), the has_many collection
parent.children includes the unsaved child. However the belongs_to
attribute child.parent appears to be nil until the parent has been
saved. Without access to the parent attributes, the validation can't
be done in the child model. I have a sort-of workaround using
validation code in the parent, but that violates DRY. The validation
still has to be in the child because the child can be updated without
the parent validation coming into play.

Here's the code:

Here's the solution:

http://macksmind.net/2008/04/26/using-belongs_to-in-rails-model-validations-when-the-parent-is-unsaved/