Relation#last removes combines
まだ誰も着手していません。
評価
調査の方向性
Start with the reproduction in the issue and trace the Relation#last, combine, and reverse.first entry points. Compare how these operations load combined tags, then verify that articles.combine(:tags).last includes the associated tags just like reverse.first. The issue provides no test file or implementation path, so locate the relevant relation tests before making changes.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Using #last on a Relation, after a using #combine, ignores the combine and just returns the regular tuple.
To Reproduce
require "rom"
Types = Dry.Types()
module Structs
class Article < ROM::Struct
# Including `title` and `body` is optional, we are able to declare struct-only attributes
# If you comment these two lines out, we get the same result and same error
attribute :title, Types::String
attribute :body, Types::String
attribute :favorites_count, Types::Integer
end
end
rom = ROM.container(:sql, "sqlite::memory") do |conf|
conf.default.create_table(:articles) do
primary_key :id
column :title, String, null: false
end
conf.default.create_table(:tags) do
primary_key :id
foreign_key :article_id
column :value, String, null: false
end
conf.relation(:articles) do
schema(infer: true) do
associations do
has_many :tags
end
end
end
conf.relation(:tags) do
schema(infer: true) do
associations do
belongs_to :article
end
end
end
end
articles = rom.relations[:articles]
tags = rom.relations[:tags]
articles.combine(:tags).command(:create).call(title: "First", tags: [{value: "worst"}])
articles.combine(:tags).command(:create).call(title: "Second", tags: [{value: "best"}])
puts "✅ articles.combine(:tags).first:"
puts " " + articles.combine(:tags).first.inspect
puts
puts "❌ articles.combine(:tags).last: (MISSING TAGS!)"
puts " " + articles.combine(:tags).last.inspect
puts
puts "✅ articles.combine(:tags).reverse.first:"
puts " " + articles.combine(:tags).reverse.first.inspect
Outputs:
✅ articles.combine(:tags).first:
{:id=>1, :title=>"First", :tags=>[{:id=>1, :article_id=>1, :value=>"worst"}]}
❌ articles.combine(:tags).last: (MISSING TAGS!)
{:id=>2, :title=>"Second"}
✅ articles.combine(:tags).reverse.first:
{:id=>2, :title=>"Second", :tags=>[{:id=>2, :article_id=>2, :value=>"best"}]}
Expected behavior
I would expect it would work just like articles.combine(:tags).reverse.first.
My environment
- Rom-sql 3.6
- Affects my production application: No
- Ruby version: 3.3
- OS: macOS 14.4.1
Related issues
- 主要言語
- Ruby
- スター
- 220
- フォーク
- 97
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rom-rb/rom-sql のほかの issue
-
bug help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
-
bug help wanted
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
bug help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
-
bug help wanted
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
bug help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
dependencies Difficulty: Easy Good First Issue
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
rubyforgood/casa#7325 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
davidteren/mutineer#364 ·
メンテナーはふだん 2 日以内に返信
-
first-contributor first-contributors good first issue help wanted json medium up-for-grabs
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
fork-commit-merge/fork-commit-merge#8526 ·
メンテナーはふだん 1 日以内に返信