@blazetrails/activerecord
ORM layer mirroring Ruby's ActiveRecord, built on @blazetrails/arel and @blazetrails/activemodel
| Measure | Value |
|---|---|
| Rails counterpart | activerecord v8.0.5.2 |
| API methods matched | 99% (7022 of 7037) |
| Rails tests matched | 100% (2943 of 2943) (47 permanent) |
| Ruby files ported | 308 |
| Ruby files unported | 0 |
| Measured at | fe89b44726 |
Gaps by file
Ported files with Rails methods or tests still missing, largest gap first.
| Ruby file | TypeScript file | Methods missing | Tests matched |
|---|---|---|---|
adapter_helper.rb | adapter-helper.ts | 15 | — |
Missing methods
The Rails methods parity:api finds no TypeScript counterpart for, by Ruby file.
adapter_helper.rb: 15 missing
supports_savepoints?, supports_partial_index?, supports_partitioned_indexes?, supports_expression_index?, supports_index_include?, supports_insert_returning?, supports_insert_on_duplicate_skip?, supports_insert_on_duplicate_update?, supports_insert_conflict_target?, supports_optimizer_hints?, supports_datetime_with_precision?, supports_nulls_not_distinct?, supports_identity_columns?, supports_virtual_columns?, supports_native_partitioning?
Unported Ruby files
Every compared Ruby file has a TypeScript file.
Deviation receipts
JSDoc receipt tags in the package's source, by the receipt each carries.
| Tag | PERMANENT | CONVERGEABLE | none |
|---|---|---|---|
@noRailsEquivalent | 44 | 20 | 0 |
@missingRailsCall | 15 | 17 | 0 |
@missingRailsArgs | 3 | 0 | 0 |
@missingRailsName | 58 | 0 | 0 |
@inventedArm | 128 | 40 | 0 |
@perf | 8 | 0 | 0 |
@inlinedFrom | 0 | 0 | 29 |
@internal | 0 | 0 | 1857 |
Permanently skipped tests
No section cited (21)
- packages/activerecord/test/cases/associations/has-and-belongs-to-many-associations.test.ts:240
- destroy_association_async_job error shows a missing parent job class, as if ActiveJob were missing
- packages/activerecord/test/cases/inheritance.test.ts:114
- packages/activerecord/test/cases/inheritance.test.ts:118
- packages/activerecord/test/cases/inheritance.test.ts:122
- packages/activerecord/test/cases/inheritance.test.ts:399
- no locks no wait
- packages/activerecord/test/cases/query-cache.test.ts:238
- packages/activerecord/test/cases/query-cache.test.ts:241
- packages/activerecord/test/cases/query-cache.test.ts:628
- packages/activerecord/test/cases/query-cache.test.ts:671
- packages/activerecord/test/cases/query-cache.test.ts:674
- packages/activerecord/test/cases/query-cache.test.ts:1079
- packages/activerecord/test/cases/reaper.test.ts:169
- packages/activerecord/test/cases/reload-models.test.ts:5
- default scoping with threads
- default scope is threadsafe
- packages/activerecord/test/cases/transactions.test.ts:1022
- packages/activerecord/test/cases/transactions.test.ts:1428
- packages/activerecord/test/cases/transactions.test.ts:1784
- packages/activerecord/test/cases/transactions.test.ts:1787
Relation is evaluated by an async query (records, and the predicates it carries) (2)
Method visibility is compile-time only (Module#private, basic_obj_respond_to's pub) (6)
Records are not Proxies (method_missing) (1)
Ruby idioms that do not translate literally (1)
inherited is deferred to own-property memo guards (ModelSchema.inherited) (2)
Runtime facts Node does not expose (4)
Ruby Strings are JS string primitives (no mutable String carrier) (3)
Ratified deviations
Each rule below is ratified in the repository's CLAUDE.md files. The first paragraph is quoted; the link opens the full section at this build's commit.
Ruby idioms that do not translate literally
These are the recurring silent-divergence traps. Check each one whenever you port a body:
Method visibility is compile-time only (Module#private, basic_obj_respond_to's pub)
Ruby's basic_obj_respond_to (vendor/ruby/v3.3.11/vm_method.c:2864-2879) takes a pub flag and hands it to method_boundp (:1788-1818), so respond_to?(:m) and respond_to?(:m, true) can answer differently for the same receiver, and Kernel#public_send (vm_eval.c:1350) raises NoMethodError "private method '…' called for …" where send dispatches. Visibility is a property of the method entry, readable at run time.
Ruby Strings are JS string primitives (no mutable String carrier)
A Ruby String is a mutable object with identity. str << "x" and str.replace("y") change the receiver in place, str.dup is a second object with the same content, and frozen? is a per-object fact. ActiveModel leans on all three:
Runtime facts Node does not expose
Each of these is a Ruby or C-library fact with no Node source. They are ratified here so no port re-derives them.
inherited is deferred to own-property memo guards (ModelSchema.inherited)
§ "Module mixins" says only inherited has no JS equivalent. JS has no hook that fires when class Child extends Parent is evaluated, so wherever Rails' inherited resets or seeds per-class state, trails defers it to the first read or first write on the subclass: a memo is answered only when it is an own property of the class being asked (Object.hasOwn(host, key)), so an inherited memo reads as unset — the observable state inherited's reset leaves behind — with nothing running at definition time. A lazy reset at first read would clobber memos written to the child before it, and a decorator or registration step on every model is invented Rails-facing surface. This is a genuine language shortcoming, ratified repo-wide; an own-property memo guard is the port of inherited, not a deviation to retire, and there is no story to port inherited as a hook.
Relation is evaluated by an async query (records, and the predicates it carries)
Ruby's Relation is an Enumerable, and every call that needs the records themselves reaches them through records (activerecord/lib/active_record/relation.rb:342-345), which calls load (:1179-1186) and runs the query synchronously; an unloaded size is count(:all) and an unloaded empty? is !exists? (:352-369), also synchronous. So a Relation is both the query and its result, and a predicate that needs a second query can run it in place.
packages/activerecord/CLAUDE.md →
The pool monitor guards only sections that span an await (ConnectionPool's MonitorMixin)
Rails' ConnectionPool is a monitor (include MonitorMixin, activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:217), and trails' takes that monitor through ruby-compat's synchronize, keyed on the receiver (synchronize.call(this, block) is Ruby's bare synchronize do). A monitor excludes other callers only while its holder is suspended, and a JS body with no await cannot be suspended, so a synchronize do whose trails body is synchronous is already atomic and wrapping it would change only its return type.
packages/activerecord/CLAUDE.md →
Schema reflection peeks at a warm cache (load_schema!'s schema_cache.columns_hash)
Rails' ModelSchema#load_schema! (activerecord/lib/active_record/model_schema.rb:587-597) reads schema_cache.columns_hash(table_name) synchronously, and a cold cache just runs the reflection query in line. In trails a cold cache needs an awaited query and a warm cache needs nothing, so the divergence is confined to the cold path and the settled shape splits it the same way:
packages/activerecord/CLAUDE.md →
The adapter lock defaults to a monitor, not NullLock
Rails' AbstractAdapter#initialize ends with self.lock_thread = nil (activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:157), and lock_thread= (:181-191) maps nil to ActiveSupport::Concurrency::NullLock; only a pinned connection gets a real monitor (connection_pool.rb:335). That is safe in Ruby because a lease is per execution context and a thread runs one statement at a time. In JS one async context holds many in-flight promises, so Promise.all([Post.count(), Post.first()]) hands one adapter to two concurrent statements, and nothing in the (faithfully keyed) lease registry serializes them.
packages/activerecord/CLAUDE.md →
inherited is deferred to own-property memo guards (ModelSchema.inherited)
Eight modules under ActiveRecord::Base define inherited, and each runs at class-definition time, super first: Core (activerecord/lib/active_record/core.rb:412-430), AttributeMethods (attribute_methods.rb:265-272), PrimaryKey (attribute_methods/primary_key.rb:143-150), Persistence (persistence.rb:301-307), Inheritance (inheritance.rb:287-294), ModelSchema (model_schema.rb:574-580), Reflection (reflection.rb:142-147) and Locking::Optimistic (locking/optimistic.rb:194-199). Between them they reset a subclass's memos to nil or a default and seed two things: the find-by statement cache and the generated modules. JS has no definition-time hook, and a static read on the child walks the prototype chain to the parent's value.
packages/activerecord/CLAUDE.md →
A model is seated by the loader or constSet (the class keyword's constant and its inherited)
A Ruby class Foo < ActiveRecord::Base does two things at the class keyword. It binds the constant Foo, which is what compute_type (activerecord/lib/active_record/inheritance.rb:242-268) and constantize later resolve a class_name: or a stored STI / polymorphic type against. And it makes Foo a subclass of its parent as Ruby sees it: inherited (inheritance.rb:287-294) fires, and Foo is in the parent's Class#subclasses, which DescendantsTracker reads.
packages/activerecord/CLAUDE.md →
A create path awaits its block before saving (create's &block)
Rails' create paths yield the caller's block synchronously while building the record and save only afterwards: Persistence::ClassMethods#create / create! (activerecord/lib/active_record/persistence.rb:33-58) call new(attributes, &block) before save, CollectionAssociation#_create_record (associations/collection_association.rb:353-373) calls build_record before opening transaction, and SingularAssociation#_create_record (associations/singular_association.rb:67-73) calls it before record.save. So a block that queries sees the pre-INSERT state (has_many_associations_test.rb:2727-2745), and a block that assigns sees its writes saved.
packages/activerecord/CLAUDE.md →
Trilogy is out of scope (trilogy_adapter.rb, adapters/trilogy/)
Rails ships a second MySQL adapter over Trilogy, a C client library with Ruby bindings. Trilogy has no Node client and trails will not port it: a TrilogyAdapter built on the mysql2 npm driver would be a second Mysql2Adapter under a Rails name that means "not mysql2". MySQL goes through Mysql2Adapter.
packages/activerecord/CLAUDE.md →
ActiveRecord::Promise is the native promise (promise.rb, Promise::Complete)
Rails' ActiveRecord::Promise (activerecord/lib/active_record/promise.rb) is a BasicObject over a thread-backed FutureResult whose value (:20-29) blocks until the query completes; Promise::Complete (:63-81) is the same surface over a value already there, returned by the async_* readers when there is no query to wait for. The native JS promise is the port. promise.rb is not ported and stays in scripts/parity/unported-files/unscoped.ts; every async_* reader returns a native promise, and so does the reader it wraps. A complete port was written and dropped on the maintainer's decision (2026-10-01): value cannot be ported, an async function unwraps any thenable it returns, and with both pluck and async_pluck awaited there is nothing left to tell apart.
packages/activerecord/CLAUDE.md →
Adapter facts are prewarmed and peeked (lookup_cast_type, max_identifier_length, quote_string)
Some synchronous Rails bodies ask the adapter a question only the server can answer, and ask it in line:
packages/activerecord/CLAUDE.md →
Fixtures load from .ts modules as well as YAML (FixtureSet::File)
Rails reads a fixture file through FixtureSet::File#raw_rows (activerecord/lib/active_record/fixture_set/file.rb:51-53), which is ActiveSupport::ConfigurationFile.parse over YAML. trails also accepts a fixture as a .ts module registered through File.registerModule, and the canonical test fixtures ship that way.
packages/activerecord/CLAUDE.md →
Call-time constant resolution (activerecord)
The activerecord inventory for root CLAUDE.md § "Call-time constant resolution". activerecord/lib/namespaces.ts holds the ActiveRecord, ActiveRecord::Associations, ActiveRecord::ConnectionAdapters, ActiveRecord::Encryption and ActiveRecord::Tasks namespace objects, extended with ActiveSupport::Autoload like arel's, mirroring active_record.rb:43-112, associations.rb:15,29-41 and encryption.rb:10-35. Each constant is seated by the module that defines it.
packages/activerecord/CLAUDE.md →
An adapter file is loaded by an awaited step (ConnectionAdapters.resolve's require)
Rails loads an adapter inside ConnectionAdapters.resolve: a synchronous require path_to_adapter under a rescue LoadError (activerecord/lib/active_record/connection_adapters.rb:42-56). resolve is reached synchronously through DatabaseConfig#adapter_class (database_configurations/database_config.rb:17-19) by quoted_table_name (model_schema.rb:286), quoted_primary_key (attribute_methods/primary_key.rb:92) and disallow_raw_sql! (sanitization.rb:183), so it cannot be a promise.
packages/activerecord/CLAUDE.md →
A migration file is loaded by Kernel#load (MigrationProxy#load_migration)
Rails' MigrationProxy#load_migration (activerecord/lib/active_record/migration.rb:1196-1201) is Object.send(:remove_const, name) rescue nil, load(File.expand_path(filename)), name.constantize.new(name, version). load evaluates the file every time it is called, and the file binds its class as a top-level constant.
packages/activerecord/CLAUDE.md →
A dumped statement wraps its trailing options in braces (SchemaDumper's parts.join(", "))
Rails builds a dumped statement as a list of parts and joins it: " #{parts.join(', ')}" (activerecord/lib/active_record/connection_adapters/postgresql/schema_dumper.rb:44-62,65-82, activerecord/lib/active_record/schema_dumper.rb:290,341). The first part is the call and the rest are keyword arguments, which Ruby writes with no delimiter around them.
packages/activerecord/CLAUDE.md →
SQLite's busy handler runs between steps (busy_handler, execute_batch2)
sqlite3-ruby's busy_handler runs inside the native step (sqlite3 lib/sqlite3/database.rb:692-705). A JS callback there could not await, so a wait would block the event loop holding the lock's other side. retryBusy runs the handler between steps instead, and the driver's own busy_timeout is always 0: timeout waits and yields, retries retries, and a config with neither raises at once. Statements, the configured pragmas and every other driver call the adapter makes go through retryBusy. execBatch splits a batch with sqlite3_complete's state machine and steps each statement, so a retry resumes at the blocked one. SQLite skips the handler where waiting would deadlock, and no driver reports that case apart from an ordinary SQLITE_BUSY, so the adapter tracks it: a write that follows a SELECT or WITH in an open transaction raises at once, including a SELECT that took no lock. A SAVEPOINT after the read clears the tracking, and a -- comment before the SELECT hides it, so those writes wait for the deadline. This is a genuine language shortcoming, ruled permanent by the operator on 2026-11-01 (trails#9582), and @noRailsEquivalent PERMANENT on those functions points at it.
packages/activerecord/CLAUDE.md →
Records are not Proxies (method_missing)
Ruby reaches NoMethodError for an undefined name through BasicObject#method_missing, and ActiveRecord regenerates undefined attribute methods from the same hook. So topic.mumbo and topic.mumbo = 5 raise at run time (activerecord/test/cases/attribute_methods_test.rb:641-645), and a read off an existing record after undefine_attribute_methods redefines the reader (attribute_methods_test.rb:1098).
packages/activerecord/CLAUDE.md →
A record is built with new Klass only (Inheritance::ClassMethods#new)
Ruby has one way to build a record, Klass.new(attributes, &block), and Inheritance::ClassMethods#new (activerecord/lib/active_record/inheritance.rb:56-78) overrides it: it raises NotImplementedError for an abstract class or Base, resolves an STI subclass through subclass_from_attributes, and calls subclass.new or super.
packages/activerecord/CLAUDE.md →
A ClassMethods#new that runs after super (Deduplicable)
A runtime fact Node does not expose (root § "Runtime facts Node does not expose").
packages/activerecord/CLAUDE.md →
SQLite's double-quoted-string setting
A runtime fact Node does not expose (root § "Runtime facts Node does not expose").
packages/activerecord/CLAUDE.md →
method_missing definers in this package
Class-specific rules under root § "Ruby protocol methods with a different JS mechanism"; its cross-table rules and docs/method-missing-definers.md apply too.