Skip to content

Commit 9bf2eeb

Browse files
authored
Add ActiveRecord::Relation#table_name type (#1010)
* Add ActiveRecord::Relation#table_name type ## Overview `ActiveRecord::Relation#table_name` is delegated to the model class via `method_missing`, but it was not defined in the RBS type definitions. This causes Steep to report a `NoMethodError` when calling `table_name` on a Relation instance. This PR adds the `table_name` method definition to `ActiveRecord::Relation` with a return type of `String`. ## References - Source: `ActiveRecord::ModelSchema::ClassMethods#table_name` - https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-table_name - https://github.com/rails/rails/blob/v7.0.8/activerecord/lib/active_record/model_schema.rb#L247-L250 * Move table_name definition from ActiveRecord::Relation to ActiveRecord::Delegation
1 parent 9fe4350 commit 9bf2eeb

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

gems/activerecord/6.0/activerecord.rbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ module ActiveRecord
403403
end
404404
end
405405

406+
module ActiveRecord
407+
module Delegation
408+
def table_name: () -> String
409+
end
410+
end
411+
406412
module ActiveRecord
407413
class Relation
408414
module Methods[Model, PrimaryKey]

gems/activerecord/7.2/_test/activerecord-7.2.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ class Article < ApplicationRecord
8989
User.order(:id).unscope(:order)
9090
User.reorder(id: :asc)
9191
User.order(id: :asc).reorder(id: :desc)
92+
93+
User.all.table_name
9294
end

gems/activerecord/7.2/activerecord.rbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ module ActiveRecord
410410
end
411411
end
412412

413+
module ActiveRecord
414+
module Delegation
415+
def table_name: () -> String
416+
end
417+
end
418+
413419
module ActiveRecord
414420
class Relation
415421
module Methods[Model, PrimaryKey]

gems/activerecord/8.0/_test/activerecord-8.0.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ class Article < ApplicationRecord
8989
User.order(:id).unscope(:order)
9090
User.reorder(id: :asc)
9191
User.order(id: :asc).reorder(id: :desc)
92+
93+
User.all.table_name
9294
end

gems/activerecord/8.0/activerecord.rbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ module ActiveRecord
410410
end
411411
end
412412

413+
module ActiveRecord
414+
module Delegation
415+
def table_name: () -> String
416+
end
417+
end
418+
413419
module ActiveRecord
414420
class Relation
415421
module Methods[Model, PrimaryKey]

0 commit comments

Comments
 (0)