Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activerecord: Add AR::Relation#sanitize_sql_like #691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gems/activerecord/6.0/_test/activerecord-generated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class User < ActiveRecord::Base
validates :name, presence: true, if: -> { something }
validates :age, presence: true, if: ->(user) { user.something }

scope :name_like, ->(name) { where(arel_table[:name].matches("%#{sanitize_sql_like(name)}%")) }
scope :matured, -> { where(arel_table[:age].gteq(18)) }

before_save -> (obj) { obj.something; self.something }
Expand Down
5 changes: 5 additions & 0 deletions gems/activerecord/6.0/activerecord.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ module ActiveRecord
# user.name # => Oscar
def new: (?untyped? attributes) ?{ () -> untyped } -> untyped

# ActiveRecord::Relation delegates method calls to a ActiveRecord::Base class.
# To represent the behavior in the RBS system, we define and include the class methods of ActiveRecord::Base here.

include Sanitization::ClassMethods

def arel_table: () -> Arel::Table
end
end
Expand Down