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

belongs_to singular version of key

belongs_to should be singular and has_many should be plural. Somehow code does not run? Gives me an error that 'belongs_to' always wants singular version which I think I have.

models.rb
class BlogPost < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :blogpost
end

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey David,

This is one of the more tricky challenges. The question give you a bit of a clue when is mentions that there is a blog_post_id column... kind of saying that there is also a blog_post (with an underscore) column and that is the "singular" the challenge is looking for. The rest of you code is correct. Keep Coding! :)

class BlogPost < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :blog_post
end

:dizzy:

Each word is critical David