2019-10-01から1ヶ月間の記事一覧
自己結合 自己テーブルを参照する関連も作ることができる class AddColumnToPosts < ActiveRecord::Migration[6.0] def change add_reference :posts, :prev_post add_reference :posts, :next_post end end class Post < ApplicationRecord belongs_to :cat…
Association extensions # Post::ActiveRecord_Associations_CollectionProxy に hoge メソッドを生やす. # 当然メソッド内でのselfはPst::ActiveRecord_Associations_CollectionProxyで posts が入っている。 # CollectionProxyに生えているので 当然 Post.…