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

Filter values for related resources are wrapped in nested arrays?

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
rails, ruby
領域
api, backend

調査の方向性

lib/jsonapi/resource.rb の 753 行付近から始め、フィルター値の処理をコミット 3a691b2 と比較します。issue で説明されているカスタムフィルターのケースを再現し、Resource#verify_resource がネストした配列を引き起こすか確認します。関連リソースのフィルター値が不要にラップされず、文字列のパースが引き続き機能すれば完了です。issue ではテストファイルは指定されていません。

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

説明

I'm a little confused as to what's going on, but upgrading from 0.8.3 to 0.9 broke some filters I have in place. e.g.:

VERIFY_RADIUS_FILTER = ->(value, context) {
  return NoLimit.new unless context[:current_location].present?

  value
}

FILTER_RADIUS_FROM_LOCATION = ->(records, value, options) {
  location = options.dig(:context, :current_location)
  limit = Array(value).first

  return records unless location.present? && limit.present?

  records.near(location, Float(limit))
}

filter :radius, default: 100.0,
                verify: VERIFY_RADIUS_FILTER,
                apply: FILTER_RADIUS_FROM_LOCATION

I think this commit my be the culprit? https://github.com/cerebris/jsonapi-resources/commit/3a691b29adb3e7aff0743ef59e44556bedb260c9

From what I can tell, this results in Resource#verify_resource being called twice. For a custom filter, at least (which is what I've got), that means the raw value gets doubly-nested in an array: https://github.com/cerebris/jsonapi-resources/blob/19f4d7b59f92b05fa28c4f925391cf5998123308/lib/jsonapi/resource.rb#L753

Instead I wonder if that line should be something like:

filter_values += raw.is_a?(String) ? CSV.parse_line(raw) : Array(raw)

To make sure we don't wrap an array?

/cc @hidde-jan

主要言語
Ruby
スター
2.3k
フォーク
546
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

JSONAPI-Resources/jsonapi-resources のほかの issue

JSONAPI-Resources/jsonapi-resources の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

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

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