Skip to content

Commit

Permalink
Revert "Revert "Merge pull request rails#7661 from ernie/build-join-r…
Browse files Browse the repository at this point in the history
…ecords-on-unsaved-hmt""

This reverts commit 18b9187.
  • Loading branch information
pivotalcb committed Mar 19, 2013
1 parent a4b5582 commit 85801df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 0 additions & 6 deletions activerecord/CHANGELOG.md
Expand Up @@ -113,12 +113,6 @@

*Andrew White*

* Revert creation of through association models when using `collection=[]`
on a `has_many :through` association from an unsaved model.
Fix #7661, #8269.

*Ernie Miller*

* Fix undefined method `to_i` when calling `new` on a scope that uses an
Array; Fix FloatDomainError when setting integer column to NaN.
Fixes #8718, #8734, #8757.
Expand Down
Expand Up @@ -38,6 +38,20 @@ def concat(*records)
super
end

def concat_records(records)
ensure_not_nested

records = super

if owner.new_record? && records
records.flatten.each do |record|
build_through_record(record)
end
end

records
end

def insert_record(record, validate = true, raise = false)
ensure_not_nested

Expand Down
Expand Up @@ -862,6 +862,11 @@ def test_save_should_not_raise_exception_when_join_record_has_errors
end
end

def test_assign_array_to_new_record_builds_join_records
c = Category.new(:name => 'Fishing', :authors => [Author.first])
assert_equal 1, c.categorizations.size
end

def test_create_bang_should_raise_exception_when_join_record_has_errors
repair_validations(Categorization) do
Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
Expand Down

0 comments on commit 85801df

Please sign in to comment.