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 trialDamian Sieczkowski
9,730 Pointshas_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
6 Answers
Mikal Chawdry
5,571 PointsI 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
8,992 Pointstry :blog_post instead of :blogpost
Damian Sieczkowski
9,730 PointsNice - thanks guys! Did not realize I needed an underscore there.
Mikal Chawdry
5,571 Pointsno problem!
Damian Sieczkowski
9,730 PointsWould you be interested in answering a MySql challenge question?
https://teamtreehouse.com/forum/groupingjoiningandcleaningup-challenge-task-1
Mikal Chawdry
5,571 PointsDon't know much SQL. Wouldn't be able to help you there.
Damian Sieczkowski
9,730 PointsCool. Thought I'd try!
jay niceness
7,406 PointsWhy did this require an underscore blog_post vs blogpost ? the model says BlogPost