diff options
author | gregolsen <anotheroneman@yahoo.com> | 2012-01-31 11:48:26 +0200 |
---|---|---|
committer | gregolsen <anotheroneman@yahoo.com> | 2012-01-31 11:52:23 +0200 |
commit | f13a1dd781d57128cd53a9b070248b8bc13edaeb (patch) | |
tree | 93a806aa2b01a5a514fecb0e87291bb37fd49cab /activerecord | |
parent | 920030b3d58b0fa1e5600e9573d82d561f22aff1 (diff) | |
download | rails-f13a1dd781d57128cd53a9b070248b8bc13edaeb.tar.gz rails-f13a1dd781d57128cd53a9b070248b8bc13edaeb.tar.bz2 rails-f13a1dd781d57128cd53a9b070248b8bc13edaeb.zip |
ids_reader method fixed, test added to has_many association
Diffstat (limited to 'activerecord')
3 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 7aed64d48c..b2136605e1 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -58,7 +58,7 @@ module ActiveRecord end end - relation.uniq.pluck(column) + relation.pluck(column) end end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index f1a341437f..b1b0768aab 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1253,6 +1253,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert company.clients_using_sql.loaded? end + def test_get_ids_for_ordered_association + assert_equal [companies(:second_client).id, companies(:first_client).id], companies(:first_firm).clients_ordered_by_rating_ids + end + def test_assign_ids_ignoring_blanks firm = Firm.create!(:name => 'Apple') firm.client_ids = [companies(:first_client).id, nil, companies(:second_client).id, ''] diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index d1a8a82786..764f1c1df5 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -45,6 +45,7 @@ class Firm < Company has_many :unsorted_clients_with_symbol, :class_name => :Client has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" + has_many :clients_ordered_by_rating, :order => "rating", :class_name => "Client" has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all |