Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Support for has_many-through with a join table that "has many targets"

オープン
#194 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
ruby, sqlite
領域
backend, database

調査の方向性

Start by running the Ruby reproduction against the in-memory SQLite database and compare the generated SQL with the expected joins. Trace the association handling for bookings, tickets, and passes; done means the second join uses the tickets-to-passes relationship rather than repeating the bookings-to-tickets condition.

索引モデルが issue の本文から書いたものです。

説明

discussion
require 'rom'
require 'sqlite3'

rom = ROM.container(:sql, 'sqlite::memory') do |conf|
  conf.default.create_table(:bookings) do
    primary_key :booking_id
  end

  conf.default.create_table(:tickets) do
    primary_key :ticket_id
    column :booking_id, Integer
  end

  conf.default.create_table(:passes) do
    primary_key :pass_id
    column :ticket_id, Integer
  end

  conf.relation(:bookings) do
    schema(infer: true) do
      associations do
        has_many :tickets
        has_many :passes, through: :tickets
      end
    end

    def with_passes
      join(passes)
    end
  end

  conf.relation(:tickets) do
    schema(infer: true) do
      associations do
        belongs_to :booking
        has_many :passes
      end
    end
  end

  conf.relation(:passes) do
    schema(infer: true) do
      associations do
        belongs_to :tickets
      end
    end
  end
end

joined = rom.relation(:bookings).join(rom.relation(:passes))

Expected SQL:

SELECT `bookings`.`booking_id`
FROM `bookings`
INNER JOIN `tickets` ON (`bookings`.`booking_id` = `tickets`.`booking_id`)
INNER JOIN `passes` ON (`tickets`.`ticket_id` = `passes`.`pass_id`)
ORDER BY `bookings`.`booking_id`

Actual SQL:

SELECT `bookings`.`booking_id`
FROM `bookings`
INNER JOIN `tickets` ON (`bookings`.`booking_id` = `tickets`.`booking_id`)
INNER JOIN `passes` ON (`bookings`.`booking_id` = `tickets`.`booking_id`)
ORDER BY `bookings`.`booking_id`
主要言語
Ruby
スター
220
フォーク
97
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rom-rb/rom-sql のほかの issue

rom-rb/rom-sql の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。