Skip to content

Fix relation ids generation for composite primary keys - #2724

Merged
paracycle merged 1 commit into
Shopify:mainfrom
jgrau:jgrau/fix-composite-primary-key-ids
Oct 6, 2026
Merged

paracycle merged 1 commit into
Shopify:mainfrom
jgrau:jgrau/fix-composite-primary-key-ids

Conversation

@jgrau

@jgrau jgrau commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

ActiveRecordRelations passes primary_key to ActiveRecordColumnTypeHelper#type_for while generating ids. For a composite primary key, that value is an Array, but type_for accepts a String, so DSL RBI generation raises a TypeError instead of producing relation methods.

Fixes #2723.

Implementation

Ask the helper for "id", which already delegates to its composite-aware id_type implementation. Scalar models still resolve their actual primary-key column, including nonstandard names. The existing composite find signatures are unchanged.

Tests

Added an SQLite-backed compiler regression with a three-column String/Date/Date primary key. It failed before the fix with Expected type ::String, got type Array and passes with ids returning T::Array[[::String, ::Date, ::Date]]. Added coverage for a nonstandard scalar primary key.

Use the column helper’s composite-aware id path so RBI generation accepts an array primary key and returns typed tuples. Cover composite and nonstandard scalar keys in the Relations compiler specs.

Pax-Session: interactive:terminal/01a0e468-c6cd-7049-8a4c-01fc37048a82
Pax-Origin: interactive:terminal
Co-authored-by: Pax <262454628+hey-pax@users.noreply.github.com>
@jgrau
jgrau requested a review from a team as a code owner September 28, 2026 09:51
@jgrau

jgrau commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

I have signed the CLA!

@paracycle
paracycle merged commit 69c26fc into Shopify:main Oct 6, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ActiveRecordRelations cannot generate an RBI for an Active Record model with a composite primary key

2 participants