Created
February 10, 2009 15:23
-
-
Save gaspard/61423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns whether or not the parent, <tt>self</tt>, and any loaded autosave associations are valid. | |
def valid_with_autosave_associations? | |
record_valid = valid_without_autosave_associations? | |
self.class.reflect_on_all_autosave_associations.all? do |reflection| | |
if (association = association_instance_get(reflection.name)) && association.loaded? | |
if association.is_a?(Array) | |
association.proxy_target.all? { |child| autosave_association_valid?(reflection, child) } | |
else | |
autosave_association_valid?(reflection, association) | |
end | |
else | |
true # association not loaded yet, so it should be valid | |
end | |
end && record_valid | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment