Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5180

Rails parity: Add #pick method (equivalent to pluck.first)

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 8.0.1
    • Affects Version/s: None
    • Component/s: Query
    • None
    • Fully Compatible

      https://til.hashrocket.com/posts/wcwerkn2il-rails-6-new-activerecord-method-pick

      Rails 6 includes a new convenient method on ActiveRecord pick. This method picks the first result value(s) from a ActiveRecord relation.

       
      {{}}

      Person.all.pick(:name) # SELECT people.name FROM people LIMIT 1

       
      pick(:name) is basically equivalent to limit(1).pluck(:name).first.
      Like pluck, pick(:name) returns a scalar value and pick(:name, :email) returns an array of values.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: