Skip to content

Commit

Permalink
[#447 state:resolved] Work around rails bug #3510
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlarsen committed Nov 24, 2009
1 parent 30af764 commit d984386
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hobo/lib/hobo/accessible_associations.rb
Expand Up @@ -42,8 +42,15 @@ def find_or_create_and_update(owner, association_name, finder, record_hash_or_st

record = yield id
record.attributes = hash
owner.include_in_save(association_name, record) unless owner.new_record? && record.new_record?

if owner.new_record? && record.new_record?
# work around
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3510-has_many-build-does-not-set-reverse-reflection
# https://hobo.lighthouseapp.com/projects/8324/tickets/447-validation-problems-with-has_many-accessible-true
method = "#{owner.class.reverse_reflection(association_name).name}=".to_sym
record.send(method, owner) if record.respond_to? method
else
owner.include_in_save(association_name, record)
end
else
# It's already a record
record = record_hash_or_string
Expand Down

0 comments on commit d984386

Please sign in to comment.