From 8d0b4fa39fab6e5d1e3382b4b137cc47e559b0be Mon Sep 17 00:00:00 2001 From: josevalim Date: Fri, 23 May 2008 11:20:13 +0200 Subject: Added :select option to has_one and belongs_to, remove unused :order option on belongs_to. Signed-off-by: Michael Koziarski [#241 state:resolved] --- activerecord/test/cases/associations/belongs_to_associations_test.rb | 5 +++++ activerecord/test/cases/associations/has_one_associations_test.rb | 5 +++++ activerecord/test/models/company.rb | 2 ++ 3 files changed, 12 insertions(+) mode change 100644 => 100755 activerecord/test/cases/associations/belongs_to_associations_test.rb mode change 100644 => 100755 activerecord/test/cases/associations/has_one_associations_test.rb (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb old mode 100644 new mode 100755 index 4382ba17ef..3073eae355 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -92,6 +92,11 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_not_nil Company.find(3).firm_with_condition, "Microsoft should have a firm" end + def test_with_select + assert_equal Company.find(2).firm_with_select.attributes.size, 1 + assert_equal Company.find(2, :include => :firm_with_select ).firm_with_select.attributes.size, 1 + end + def test_belongs_to_counter debate = Topic.create("title" => "debate") assert_equal 0, debate.send(:read_attribute, "replies_count"), "No replies yet" diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb old mode 100644 new mode 100755 index 9e99caa7b7..e7d4de8246 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -24,6 +24,11 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert_queries(0) { firms.each(&:account) } end + def test_with_select + assert_equal Firm.find(1).account_with_select.attributes.size, 2 + assert_equal Firm.find(1, :include => :account_with_select).attributes.size, 2 + end + def test_can_marshal_has_one_association_with_nil_target firm = Firm.new assert_nothing_raised do diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index f637490c59..cc521d2a02 100755 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -47,6 +47,7 @@ class Firm < Company has_many :readonly_clients, :class_name => 'Client', :readonly => true has_one :account, :foreign_key => "firm_id", :dependent => :destroy + has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id" has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true end @@ -64,6 +65,7 @@ end class Client < Company belongs_to :firm, :foreign_key => "client_of" belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id" + belongs_to :firm_with_select, :class_name => "Firm", :foreign_key => "firm_id", :select => "id" belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of" belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1] belongs_to :readonly_firm, :class_name => "Firm", :foreign_key => "firm_id", :readonly => true -- cgit v1.2.3