Save 36% for Black Friday! Learn more

gusmac

Joined

820 Experience
8 Lessons Completed
0 Questions Solved

Activity

Posted in Nested Comment Threads in Rails - Part 1 Discussion

bugger! typing on the train LOL! thanks

Posted in Nested Comment Threads in Rails - Part 1 Discussion

hi chris,

using the rails generate command below:
rails g model Comment user:references commentable:references{ploymorphic}:index parent_id:integer body:text

created the migration file:
class CreateComments < ActiveRecord::Migration[5.2]
def change
create_table :comments do |t|
t.references :user, foreign_key: true
t.references :commentable, ploymorphic: true, foreign_key: true
t.integer :parent_id
t.text :body

  t.timestamps
end

end
end

which failed " PG::UndefinedTable: ERROR: relation "commentables" does not exist "

i went through the github files and found that your migration file did not have the foreign_key: true on the commentable line. i reran the migration and it worked, but just out of curiosity why did the references create a foreign_key: true for my migration and not your migration.

cheers

gus

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.