aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb2
-rw-r--r--activerecord/test/associations_join_model_test.rb11
-rw-r--r--activerecord/test/fixtures/author.rb3
-rw-r--r--activerecord/test/fixtures/categorization.rb5
-rw-r--r--activerecord/test/fixtures/categorizations.yml5
-rw-r--r--activerecord/test/fixtures/db_definitions/schema.rb6
6 files changed, 29 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index f9020ebcad..9ecd6f059e 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -58,7 +58,7 @@ module ActiveRecord
else
conditions =
"#{@reflection.klass.table_name}.#{@reflection.klass.primary_key} = #{through_reflection.table_name}.#{@reflection.klass.to_s.foreign_key} " +
- "AND #{through_reflection.table_name}.#{@owner.to_s.foreign_key} = #{@owner.quoted_id}"
+ "AND #{through_reflection.table_name}.#{@owner.class.to_s.foreign_key} = #{@owner.quoted_id}"
end
conditions << " AND (#{interpolate_sql(sanitize_sql(@reflection.options[:conditions]))})" if @reflection.options[:conditions]
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb
index 07e9288f08..7b53141ccd 100644
--- a/activerecord/test/associations_join_model_test.rb
+++ b/activerecord/test/associations_join_model_test.rb
@@ -3,10 +3,17 @@ require 'fixtures/tag'
require 'fixtures/tagging'
require 'fixtures/post'
require 'fixtures/comment'
+require 'fixtures/author'
+require 'fixtures/category'
+require 'fixtures/categorization'
class AssociationsJoinModelTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
- fixtures :posts, :comments, :tags, :taggings
+ fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings
+
+ def test_has_many
+ assert_equal categories(:general), authors(:david).categories.first
+ end
def test_polymorphic_has_many
assert_equal taggings(:welcome_general), posts(:welcome).taggings.first
@@ -18,5 +25,5 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
def test_polymorphic_has_many_going_through_join_model
assert_equal tags(:general), posts(:welcome).tags.first
- end
+ end
end
diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb
index e98d15e37a..3138dfca57 100644
--- a/activerecord/test/fixtures/author.rb
+++ b/activerecord/test/fixtures/author.rb
@@ -17,6 +17,9 @@ class Author < ActiveRecord::Base
:after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id}"}]
has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
+ has_many :categorizations
+ has_many :categories, :through => :categorizations
+
attr_accessor :post_log
def after_initialize
diff --git a/activerecord/test/fixtures/categorization.rb b/activerecord/test/fixtures/categorization.rb
new file mode 100644
index 0000000000..10594323ff
--- /dev/null
+++ b/activerecord/test/fixtures/categorization.rb
@@ -0,0 +1,5 @@
+class Categorization < ActiveRecord::Base
+ belongs_to :post
+ belongs_to :category
+ belongs_to :author
+end \ No newline at end of file
diff --git a/activerecord/test/fixtures/categorizations.yml b/activerecord/test/fixtures/categorizations.yml
new file mode 100644
index 0000000000..a93fd6b79e
--- /dev/null
+++ b/activerecord/test/fixtures/categorizations.yml
@@ -0,0 +1,5 @@
+david_welcome_general:
+ id: 1
+ author_id: 1
+ post_id: 1
+ category_id: 1 \ No newline at end of file
diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb
index b839edbac0..1cf4dee7a5 100644
--- a/activerecord/test/fixtures/db_definitions/schema.rb
+++ b/activerecord/test/fixtures/db_definitions/schema.rb
@@ -10,4 +10,10 @@ ActiveRecord::Schema.define do
t.column "name", :string
end
+ create_table "categorizations", :force => true do |t|
+ t.column "category_id", :integer
+ t.column "post_id", :integer
+ t.column "author_id", :integer
+ end
+
end \ No newline at end of file