rubymonolith / superform

Build highly customizable forms in Rails
MIT License
263 stars 14 forks source link

select requires unpacking of array to work #10

Open HalfBloody opened 7 months ago

HalfBloody commented 7 months ago

Was trying:

    row field(:counterparty_id).select(
      Counterparty.pluck(:name, :id)
    )

But as a result I got.

image

It works as expected only when unpacking the array argument:

    row field(:counterparty_id).select(
      *Counterparty.pluck(:name, :id)
    )

Would be great if the select would accept an array as argument.

HalfBloody commented 7 months ago

Opened a pull request to fix that, unless there is a usecase for passing positional arguments only.

bradgessler commented 4 months ago

Try using Counterparty.select(:name, :id) instead of Counterparty.pluck(:name, :id). Pluck returns an "eager" array whereas select is a "lazy" ActiveRecord scope.

The positional arguments are intentional because the syntax is nicer. If this is a common problem I'd accept a PR that detects an array of arrays and iterates through those, which would make pluck work.