diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-06-22 12:15:42 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-06-22 12:15:42 +0200 |
commit | 5009b078875e596a2fba7827336f7548aa6e35ac (patch) | |
tree | a95880d93e4ff73befaba055db15e5f50f594dad | |
parent | 6675d713186c270de1c4684bc1e56742ea2e19e1 (diff) | |
download | rails-5009b078875e596a2fba7827336f7548aa6e35ac.tar.gz rails-5009b078875e596a2fba7827336f7548aa6e35ac.tar.bz2 rails-5009b078875e596a2fba7827336f7548aa6e35ac.zip |
Revert "Merge pull request #10901 from armstrjare/fix_query_null_foreign_key_on_new_record_collection_ids_reader"
This reverts commit 6675d713186c270de1c4684bc1e56742ea2e19e1, reversing
changes made to 919d1a19d5e7871d50c1531351fc3f736bad5d07.
I missed to check the target branch and wrongly merged it into 3-2-stable directly.
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 27 |
3 files changed, 1 insertions, 34 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index c530f7feff..199150232c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -4,12 +4,6 @@ *Yves Senn* -* Prevent query with NULL foreign key value on CollectionAssociation#ids_reader - for non-persisted records. Fixes bug where Company.new.contract_ids would - incorrectly load all non-associated Contracts. - - *Jared Armstrong* - * Fix the `:primary_key` option for `has_many` associations. Fixes #10693. diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index baddb9852f..65e882867e 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -43,7 +43,7 @@ module ActiveRecord # Implements the ids reader method, e.g. foo.item_ids for Foo.has_many :items def ids_reader - if owner.new_record? || loaded? || options[:finder_sql] + if loaded? || options[:finder_sql] load_target.map do |record| record.send(reflection.association_primary_key) end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 55b57bc2f2..a75d064ac0 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1311,33 +1311,6 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert !company.clients.loaded? end - def test_get_ids_for_association_on_new_record_does_not_try_to_find_records - Company.columns # Load schema information so we don't query below - Contract.columns # if running just this test. - - company = Company.new - assert_queries(0) do - company.contract_ids - end - - assert_equal [], company.contract_ids - end - - def test_set_ids_for_association_on_new_record_applies_association_correctly - contract_a = Contract.create! - contract_b = Contract.create! - another_contract = Contract.create! - company = Company.new(:name => "Some Company") - - company.contract_ids = [contract_a.id, contract_b.id] - assert_equal [contract_a.id, contract_b.id], company.contract_ids - assert_equal [contract_a, contract_b], company.contracts - - company.save! - assert_equal company, contract_a.reload.company - assert_equal company, contract_b.reload.company - end - def test_get_ids_ignores_include_option assert_equal [readers(:michael_welcome).id], posts(:welcome).readers_with_person_ids end |