From 0651f8cc86b2a238916321a00e8a1792fcd69946 Mon Sep 17 00:00:00 2001 From: Martin Sadler Date: Thu, 29 May 2008 16:35:23 +0100 Subject: [PATCH] failing test case for test_include_with_same_named_assoc_as_the_key (when running postgresql) --- activerecord/test/cases/associations_test.rb | 6 +++++- activerecord/test/fixtures/projects.yml | 5 +++++ activerecord/test/models/project.rb | 2 ++ activerecord/test/schema/schema.rb | 5 +++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 59349dd..3fca1ae 100755 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -27,13 +27,17 @@ require 'models/sponsor' class AssociationsTest < ActiveRecord::TestCase fixtures :accounts, :companies, :developers, :projects, :developers_projects, - :computers + :computers, :people def test_include_with_order_works assert_nothing_raised {Account.find(:first, :order => 'id', :include => :firm)} assert_nothing_raised {Account.find(:first, :order => :id, :include => :firm)} end + def test_include_with_same_named_assoc_as_the_key + assert_nothing_raised {Project.find(:all, :include => 'created_by')} + end + def test_bad_collection_keys assert_raise(ArgumentError, 'ActiveRecord should have barked on bad collection keys') do Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels') diff --git a/activerecord/test/fixtures/projects.yml b/activerecord/test/fixtures/projects.yml index 02800c7..3055bd6 100644 --- a/activerecord/test/fixtures/projects.yml +++ b/activerecord/test/fixtures/projects.yml @@ -5,3 +5,8 @@ action_controller: active_record: id: 1 name: Active Record + +active_support: + id: 3 + name: Active Support + created_by: 1 \ No newline at end of file diff --git a/activerecord/test/models/project.rb b/activerecord/test/models/project.rb index e1ab89e..cb188d0 100644 --- a/activerecord/test/models/project.rb +++ b/activerecord/test/models/project.rb @@ -1,4 +1,6 @@ class Project < ActiveRecord::Base + belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by' + has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc' has_and_belongs_to_many :readonly_developers, :class_name => "Developer", :readonly => true has_and_belongs_to_many :selected_developers, :class_name => "Developer", :select => "developers.*", :uniq => true diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 423929f..91346b7 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -313,8 +313,9 @@ ActiveRecord::Schema.define do end create_table :projects, :force => true do |t| - t.string :name - t.string :type + t.string :name + t.string :type + t.integer :created_by end create_table :readers, :force => true do |t| -- 1.5.5.1 From 95cb8b3062efb9de1cc9471b8f58320c80ef79dc Mon Sep 17 00:00:00 2001 From: Martin Sadler Date: Thu, 29 May 2008 16:44:22 +0100 Subject: [PATCH] Fix for failing test case: test_include_with_same_named_assoc_as_the_key (when running postgresql) --- .../lib/active_record/association_preload.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index a3d1f12..310fa89 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -212,7 +212,7 @@ module ActiveRecord else id_map = {} records.each do |record| - key = record.send(primary_key_name) + key = record.attributes[primary_key_name] if key mapped_records = (id_map[key.to_s] ||= []) mapped_records << record -- 1.5.5.1