create_table "blogs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.string "title" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.text "body", limit: 65535 t.string "status" t.integer "entry_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "entries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.string "title" t.text "body", limit: 65535 t.integer "blog_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end
class Blog < ApplicationRecord has_many :entries end
class Entry < ApplicationRecord belongs_to :blog has_many :comments end
class Comment < ApplicationRecord belongs_to :entry end
上記のようなtableとアソシエーションの設定でblog_idの1に紐づいているentriesのcommentを出力したく何かアドバイスを頂けますと幸いです
試したこと
https://qiita.com/leon-joel/items/f26556c9e56833983856
こちらの記事などは参考にしたのですがどうも該当しないようで技術書なども参考にしたのですがわからずじまいでした
あなたの回答
tips
プレビュー