From 8ea5c19f098561937d6cd7d816fd7d4d70de9cb4 Mon Sep 17 00:00:00 2001 From: Daichi Kamiyama <32436625+dak2@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:45:48 +0900 Subject: [PATCH] activerecord: Add types for load_async (#767) This method has been added since 7.0 - https://github.com/rails/rails/pull/41372 - https://github.com/rails/rails/blob/7-0-stable/activerecord/CHANGELOG.md --- gems/activerecord/7.0/_test/test.rb | 1 + gems/activerecord/7.0/activerecord-7.0.rbs | 4 ++++ gems/activerecord/7.1/_test/test.rb | 1 + gems/activerecord/7.1/activerecord-7.1.rbs | 2 ++ gems/activerecord/7.2/_test/test.rb | 1 + gems/activerecord/7.2/activerecord-7.2.rbs | 1 + 6 files changed, 10 insertions(+) diff --git a/gems/activerecord/7.0/_test/test.rb b/gems/activerecord/7.0/_test/test.rb index 7c627a82..979c7f51 100644 --- a/gems/activerecord/7.0/_test/test.rb +++ b/gems/activerecord/7.0/_test/test.rb @@ -26,6 +26,7 @@ class Article < ActiveRecord::Base end User.where.missing.to_sql + User.where(role: :admin).load_async User.deterministic_encrypted_attributes User.source_attribute_from_preserved_attribute(:phrase) User.insert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true) diff --git a/gems/activerecord/7.0/activerecord-7.0.rbs b/gems/activerecord/7.0/activerecord-7.0.rbs index f5f20277..4fce4c6e 100644 --- a/gems/activerecord/7.0/activerecord-7.0.rbs +++ b/gems/activerecord/7.0/activerecord-7.0.rbs @@ -8,6 +8,10 @@ module ActiveRecord end end + class Relation + def load_async: () -> Relation + end + module Core def values_at: (*Symbol | String) -> Array[untyped] def strict_loading!: (?bool value, ?mode: Symbol) -> bool diff --git a/gems/activerecord/7.1/_test/test.rb b/gems/activerecord/7.1/_test/test.rb index 4cbcec91..b5a4409d 100644 --- a/gems/activerecord/7.1/_test/test.rb +++ b/gems/activerecord/7.1/_test/test.rb @@ -33,6 +33,7 @@ class Article < ActiveRecord::Base end User.where.missing.to_sql + User.where(role: :admin).load_async User.deterministic_encrypted_attributes User.source_attribute_from_preserved_attribute(:phrase) User.insert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true) diff --git a/gems/activerecord/7.1/activerecord-7.1.rbs b/gems/activerecord/7.1/activerecord-7.1.rbs index 1ddcc4a0..2fc9e596 100644 --- a/gems/activerecord/7.1/activerecord-7.1.rbs +++ b/gems/activerecord/7.1/activerecord-7.1.rbs @@ -176,6 +176,8 @@ end module ActiveRecord class Relation + def load_async: () -> Relation + module Methods[Model, PrimaryKey] def authenticate_by: (untyped attributes) -> Model? end diff --git a/gems/activerecord/7.2/_test/test.rb b/gems/activerecord/7.2/_test/test.rb index a0575219..0d2a64c5 100644 --- a/gems/activerecord/7.2/_test/test.rb +++ b/gems/activerecord/7.2/_test/test.rb @@ -31,6 +31,7 @@ class Article < ApplicationRecord end User.where.missing.to_sql + User.where(role: :admin).load_async User.deterministic_encrypted_attributes User.source_attribute_from_preserved_attribute(:phrase) User.insert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true) diff --git a/gems/activerecord/7.2/activerecord-7.2.rbs b/gems/activerecord/7.2/activerecord-7.2.rbs index d551ecbd..44c100fb 100644 --- a/gems/activerecord/7.2/activerecord-7.2.rbs +++ b/gems/activerecord/7.2/activerecord-7.2.rbs @@ -29,6 +29,7 @@ module ActiveRecord def insert_all!: (untyped attributes, ?returning: untyped?, ?record_timestamps: bool?) -> untyped def upsert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped + def load_async: () -> Relation end module Inheritance