rails icon indicating copy to clipboard operation
rails copied to clipboard

Pattern matching APIs for records and relations.

Open kddnewton opened this issue 1 year ago • 6 comments

This provides the Ruby 2.7+ pattern matching interface for Active Record records and relations. It allows the user to pattern match against attributes and associations on records through a hash pattern. It also allows the user to pattern match against relations through an array pattern.

class Post < ActiveRecord::Base
  has_many :comments

class Comment < ActiveRecord::Base
  belongs_to :post

post = Post.new(title: "Welcome!", comments: [Comment.new(body: "Thanks!")])
post => { title: "Welcome!", comments: [Comment[body:]] }
body # => "Thanks!"

kddnewton avatar May 12 '22 00:05 kddnewton

cc @gmcgibbon since you kindly merged the last one

kddnewton avatar May 12 '22 00:05 kddnewton

What's the status of this? Still blocked? I've been using this in production and it's working great.

ezekg avatar Aug 10 '22 21:08 ezekg

Here you can read the status of this https://github.com/rails/rails/pull/45553#issuecomment-1179568855

rafaelfranca avatar Aug 10 '22 21:08 rafaelfranca

@rafaelfranca, I saw that but @kddnewton hasn't gotten a response in nearly a month. I agree with his reasoning.

Would hate to see this get lost. I don't see a problem with the current API.

ezekg avatar Aug 10 '22 21:08 ezekg

We don't need to rush a decision here. Rails 7.1 isn't due any time soon and this feature would only be release in Rails 7.1. Rushing a making the wrong decision will just cause trouble for us maintainers, so it is better to make sure we have considered all possibilities.

rafaelfranca avatar Aug 10 '22 22:08 rafaelfranca

Understood, @rafaelfranca. Is there a location where this discussion is taking place?

ezekg avatar Aug 11 '22 00:08 ezekg