@@ -7,20 +7,6 @@ private import codeql.ruby.ast.internal.Module
77private import codeql.ruby.ApiGraphs
88private import codeql.ruby.frameworks.StandardLibrary
99
10- private class ActiveRecordBaseAccess extends ConstantReadAccess {
11- ActiveRecordBaseAccess ( ) {
12- this .getName ( ) = "Base" and
13- this .getScopeExpr ( ) .( ConstantAccess ) .getName ( ) = "ActiveRecord"
14- }
15- }
16-
17- // ApplicationRecord extends ActiveRecord::Base, but we
18- // treat it separately in case the ApplicationRecord definition
19- // is not in the database
20- private class ApplicationRecordAccess extends ConstantReadAccess {
21- ApplicationRecordAccess ( ) { this .getName ( ) = "ApplicationRecord" }
22- }
23-
2410/// See https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html
2511private string activeRecordPersistenceInstanceMethodName ( ) {
2612 result =
@@ -41,26 +27,28 @@ private predicate isBuiltInMethodForActiveRecordModelInstance(string methodName)
4127}
4228
4329/**
44- * A `ClassDeclaration` for a class that extends `ActiveRecord::Base`. For example,
30+ * A `ClassDeclaration` for a class that inherits from `ActiveRecord::Base`. For example,
4531 *
4632 * ```rb
4733 * class UserGroup < ActiveRecord::Base
4834 * has_many :users
4935 * end
36+ *
37+ * class SpecialUserGroup < UserGroup
38+ * end
5039 * ```
5140 */
5241class ActiveRecordModelClass extends ClassDeclaration {
5342 ActiveRecordModelClass ( ) {
5443 // class Foo < ActiveRecord::Base
55- this .getSuperclassExpr ( ) instanceof ActiveRecordBaseAccess
56- or
57- // class Foo < ApplicationRecord
58- this .getSuperclassExpr ( ) instanceof ApplicationRecordAccess
59- or
6044 // class Bar < Foo
61- exists ( ActiveRecordModelClass other |
62- other .getModule ( ) = resolveConstantReadAccess ( this .getSuperclassExpr ( ) )
63- )
45+ this .getSuperclassExpr ( ) =
46+ [
47+ API:: getTopLevelMember ( "ActiveRecord" ) .getMember ( "Base" ) ,
48+ // In Rails applications `ApplicationRecord` typically extends `ActiveRecord::Base`, but we
49+ // treat it separately in case the `ApplicationRecord` definition is not in the database.
50+ API:: getTopLevelMember ( "ApplicationRecord" )
51+ ] .getASubclass * ( ) .getAUse ( ) .asExpr ( ) .getExpr ( )
6452 }
6553
6654 // Gets the class declaration for this class and all of its super classes
0 commit comments