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

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.