Skip to content

Commit

Permalink
Fixed that has_many :through associations should render as collection…
Browse files Browse the repository at this point in the history
…s too (closes #9051) [mathie/danger]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8130 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Nov 12, 2007
1 parent a406643 commit 55b6697
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN* *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] * Added :mouseover short-cut to AssetTagHelper#image_tag for doing easy image swaps #6893 [joost]


* Fixed handling of non-domain hosts #9479 [purp] * Fixed handling of non-domain hosts #9479 [purp]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/partials.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def render_partial(partial_path, object_assigns = nil, local_assigns = nil) #:no
else else
render("#{path}/_#{partial_name}", local_assigns) render("#{path}/_#{partial_name}", local_assigns)
end end
when Array, ActiveRecord::Associations::AssociationCollection when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Associations::HasManyThroughAssociation
if partial_path.any? if partial_path.any?
path = ActionController::RecordIdentifier.partial_path(partial_path.first) path = ActionController::RecordIdentifier.partial_path(partial_path.first)
collection = partial_path collection = partial_path
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def render_with_has_many_association
render :partial => @topic.replies render :partial => @topic.replies
end end


def render_with_has_many_through_association
@developer = Developer.find(:first)
render :partial => @developer.topics
end

def render_with_belongs_to_association def render_with_belongs_to_association
@reply = Reply.find(1) @reply = Reply.find(1)
render :partial => @reply.topic render :partial => @reply.topic
Expand Down Expand Up @@ -47,6 +52,11 @@ def test_rendering_partial_with_has_many_association
assert_template 'replies/_reply' assert_template 'replies/_reply'
end 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 def test_rendering_partial_with_belongs_to_association
get :render_with_belongs_to_association get :render_with_belongs_to_association
assert_template 'topics/_topic' assert_template 'topics/_topic'
Expand Down
3 changes: 2 additions & 1 deletion actionpack/test/fixtures/db_definitions/sqlite.sql
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ CREATE TABLE 'replies' (
'content' text, 'content' text,
'created_at' datetime, 'created_at' datetime,
'updated_at' datetime, 'updated_at' datetime,
'topic_id' integer 'topic_id' integer,
'developer_id' integer
); );


CREATE TABLE 'topics' ( CREATE TABLE 'topics' (
Expand Down
2 changes: 2 additions & 0 deletions actionpack/test/fixtures/developer.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
class Developer < ActiveRecord::Base class Developer < ActiveRecord::Base
has_and_belongs_to_many :projects has_and_belongs_to_many :projects
has_many :replies
has_many :topics, :through => :replies
end end


class DeVeLoPeR < ActiveRecord::Base class DeVeLoPeR < ActiveRecord::Base
Expand Down
2 changes: 2 additions & 0 deletions actionpack/test/fixtures/replies.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,15 @@
witty_retort: witty_retort:
id: 1 id: 1
topic_id: 1 topic_id: 1
developer_id: 1
content: Birdman is better! content: Birdman is better!
created_at: <%= 6.hours.ago.to_s(:db) %> created_at: <%= 6.hours.ago.to_s(:db) %>
updated_at: nil updated_at: nil


another: another:
id: 2 id: 2
topic_id: 2 topic_id: 2
developer_id: 1
content: Nuh uh! content: Nuh uh!
created_at: <%= 1.hour.ago.to_s(:db) %> created_at: <%= 1.hour.ago.to_s(:db) %>
updated_at: nil updated_at: nil
3 changes: 2 additions & 1 deletion actionpack/test/fixtures/reply.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
class Reply < ActiveRecord::Base class Reply < ActiveRecord::Base
belongs_to :topic, :include => [:replies] belongs_to :topic, :include => [:replies]

belongs_to :developer

validates_presence_of :content validates_presence_of :content
end end

0 comments on commit 55b6697

Please sign in to comment.