Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Migrations and Relationships Relationships

Damian Sieczkowski
Damian Sieczkowski
9,730 Points

has_many and belongs_to challenge not passing

*The Challenge... * http://teamtreehouse.com/library/relationships-3

*Question is... *

Let's say we have a BlogPost model and a Comment model that represents comments someone might leave on a blog post. The comments table includes a blog_post_id column. Please setup the relationships correctly.

Answer

class BlogPost < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :blogpost
end

Here is a screenshot

http://screencast.com/t/WWIMVtrFn1Y

6 Answers

I wrote the following and it passed for me.

class BlogPost < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :blog_post
end
Michelle Cannito
Michelle Cannito
8,992 Points

try :blog_post instead of :blogpost

Damian Sieczkowski
Damian Sieczkowski
9,730 Points

Nice - thanks guys! Did not realize I needed an underscore there.

no problem!

Don't know much SQL. Wouldn't be able to help you there.

Why did this require an underscore blog_post vs blogpost ? the model says BlogPost