rails
rails copied to clipboard
Pattern matching APIs for records and relations.
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
end
class Comment < ActiveRecord::Base
belongs_to :post
end
post = Post.new(title: "Welcome!", comments: [Comment.new(body: "Thanks!")])
post => { title: "Welcome!", comments: [Comment[body:]] }
body # => "Thanks!"
cc @gmcgibbon since you kindly merged the last one
What's the status of this? Still blocked? I've been using this in production and it's working great.
Here you can read the status of this https://github.com/rails/rails/pull/45553#issuecomment-1179568855
@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.
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.
Understood, @rafaelfranca. Is there a location where this discussion is taking place?