Created
July 13, 2011 22:40
-
-
Save metasoarous/1081500 to your computer and use it in GitHub Desktop.
assign_nested_attributes_for_one_to_one_association method definition
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
# File activerecord/lib/active_record/nested_attributes.rb, line 289 | |
def assign_nested_attributes_for_one_to_one_association(association_name, attributes) | |
options = nested_attributes_options[association_name] | |
attributes = attributes.with_indifferent_access | |
check_existing_record = (options[:update_only] || !attributes['id'].blank?) | |
if check_existing_record && (record = send(association_name)) && | |
(options[:update_only] || record.id.to_s == attributes['id'].to_s) | |
assign_to_or_mark_for_destruction(record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes) | |
elsif !attributes['id'].blank? | |
raise_nested_attributes_record_not_found(association_name, attributes['id']) | |
elsif !reject_new_record?(association_name, attributes) | |
method = "build_#{association_name}" | |
if respond_to?(method) | |
send(method, attributes.except(*UNASSIGNABLE_KEYS)) | |
else | |
raise ArgumentError, "Cannot build association #{association_name}. Are you trying to build a polymorphic one-to-one association?" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment