Wangjohn validates associated uniqueness

Pull request in response to https://github.com/rails/rails/issues/4568. Uses jeyb's pull request and cleans up some code.