rails ActiveRecord テーブル結合

本稿について

本稿はサイト運営者が学んだことなどを記したメモの内容です。
全てが正確な情報とは限りません。ご注意ください。また修正するべき点は適時修正していきます
内部結合
data = TableA.joins(:table_b).where(table_b: { data: 1 })


内部結合+検索
scope :where_contents, lambda {
    table = joins(:category)
    table.where.not(categories: { id: ID, code: ‘code' })
    .or(table.where(categories: { code: nil }))
  }

Back