1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add test_has_many_through_has_many_through_with_belongs_to_source_reflection (which already works)

This commit is contained in:
Jon Leighton 2010-10-14 13:07:28 +01:00
parent bc821a5611
commit 7963c30eba
2 changed files with 13 additions and 1 deletions

View file

@ -198,9 +198,20 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [comments(:greetings), comments(:more_greetings)], comments[2].category_post_comments
end
# TODO: has_many through
# has_many through
# Source: belongs_to
# Through: has_many through
def test_has_many_through_has_many_through_with_belongs_to_source_reflection
author = authors(:david)
assert_equal [tags(:general), tags(:general)], author.tagging_tags
authors = Author.joins(:tagging_tags).where('tags.id' => tags(:general).id)
assert_equal [authors(:david)], authors.uniq
# TODO: Make this work
# authors = Author.includes(:tagging_tags)
# assert_equal [tags(:general), tags(:general)], authors.first.tagging_tags
end
# TODO: has_many through
# Source: has_many through

View file

@ -89,6 +89,7 @@ class Author < ActiveRecord::Base
has_many :similar_posts, :through => :tags, :source => :tagged_posts
has_many :distinct_tags, :through => :posts, :source => :tags, :select => "DISTINCT tags.*", :order => "tags.name"
has_many :post_categories, :through => :posts, :source => :categories
has_many :tagging_tags, :through => :taggings, :source => :tag
has_many :books
has_many :subscriptions, :through => :books