提交 55b66974 编写于 作者: D David Heinemeier Hansson

Fixed that has_many :through associations should render as collections too...

Fixed that has_many :through associations should render as collections too (closes #9051) [mathie/danger]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8130 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 a406643b
*SVN*
* Fixed that has_many :through associations should render as collections too #9051 [mathie/danger]
* Added :mouseover short-cut to AssetTagHelper#image_tag for doing easy image swaps #6893 [joost]
* Fixed handling of non-domain hosts #9479 [purp]
......
......@@ -119,7 +119,7 @@ def render_partial(partial_path, object_assigns = nil, local_assigns = nil) #:no
else
render("#{path}/_#{partial_name}", local_assigns)
end
when Array, ActiveRecord::Associations::AssociationCollection
when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Associations::HasManyThroughAssociation
if partial_path.any?
path = ActionController::RecordIdentifier.partial_path(partial_path.first)
collection = partial_path
......
......@@ -14,6 +14,11 @@ def render_with_has_many_association
render :partial => @topic.replies
end
def render_with_has_many_through_association
@developer = Developer.find(:first)
render :partial => @developer.topics
end
def render_with_belongs_to_association
@reply = Reply.find(1)
render :partial => @reply.topic
......@@ -47,6 +52,11 @@ def test_rendering_partial_with_has_many_association
assert_template 'replies/_reply'
end
def test_rendering_partial_with_has_many_association
get :render_with_has_many_through_association
assert_template 'topics/_topic'
end
def test_rendering_partial_with_belongs_to_association
get :render_with_belongs_to_association
assert_template 'topics/_topic'
......
......@@ -9,7 +9,8 @@ CREATE TABLE 'replies' (
'content' text,
'created_at' datetime,
'updated_at' datetime,
'topic_id' integer
'topic_id' integer,
'developer_id' integer
);
CREATE TABLE 'topics' (
......
class Developer < ActiveRecord::Base
has_and_belongs_to_many :projects
has_many :replies
has_many :topics, :through => :replies
end
class DeVeLoPeR < ActiveRecord::Base
......
witty_retort:
id: 1
topic_id: 1
developer_id: 1
content: Birdman is better!
created_at: <%= 6.hours.ago.to_s(:db) %>
updated_at: nil
......@@ -8,6 +9,7 @@ witty_retort:
another:
id: 2
topic_id: 2
developer_id: 1
content: Nuh uh!
created_at: <%= 1.hour.ago.to_s(:db) %>
updated_at: nil
\ No newline at end of file
class Reply < ActiveRecord::Base
belongs_to :topic, :include => [:replies]
belongs_to :developer
validates_presence_of :content
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册