mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Allow a polymorphic :source for has_many :through associations. Closes #7143 [protocool]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -300,6 +300,18 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
|
||||
assert_equal [posts(:welcome), posts(:thinking)], tags(:general).taggings.find(:all, :include => :taggable)
|
||||
end
|
||||
end
|
||||
|
||||
def test_has_many_polymorphic_with_source_type
|
||||
assert_equal [posts(:welcome), posts(:thinking)], tags(:general).tagged_posts
|
||||
end
|
||||
|
||||
def test_eager_has_many_polymorphic_with_source_type
|
||||
tag_with_include = Tag.find(tags(:general).id, :include => :tagged_posts)
|
||||
desired = [posts(:welcome), posts(:thinking)]
|
||||
assert_no_queries do
|
||||
assert_equal desired, tag_with_include.tagged_posts
|
||||
end
|
||||
end
|
||||
|
||||
def test_has_many_through_has_many_find_all
|
||||
assert_equal comments(:greetings), authors(:david).comments.find(:all, :order => 'comments.id').first
|
||||
|
||||
2
activerecord/test/fixtures/tag.rb
vendored
2
activerecord/test/fixtures/tag.rb
vendored
@@ -2,4 +2,6 @@ class Tag < ActiveRecord::Base
|
||||
has_many :taggings
|
||||
has_many :taggables, :through => :taggings
|
||||
has_one :tagging
|
||||
|
||||
has_many :tagged_posts, :through => :taggings, :source => :taggable, :source_type => 'Post'
|
||||
end
|
||||
Reference in New Issue
Block a user