Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Shoulda gem used in Rails

I have this below code.

class CreatePosts < ActiveRecord::Migration[5.0]
  def change
    create_table :posts do |t|
      t.string :title
      t.text :body

      t.timestamps
    end
  end
end

DOES SHOULDA SOMEHOW TELL THE POSTS TABLE TO READ THE ID OF A TOPIC IT IS PART OF ? WHERE IS THE REFERENCE? LIEK THE ONE WE USED IN COMMETNS? t.references :post, foreign_key: true

I looked up the documentation for shoulda and I'm a little confused about your question. Shoulda probably just uses the default id's set up but I am not sure. You would have to go through the actual gem to see.

It mainly has methods that help with validation and testing. In Rails a primary key is made on default when you migrate your table. Then additionally if you set up a relationship between tables in your model you don't have to worry about generating foreign keys either as Rails takes care of that when you migrate again.