Rails 7.1: ActiveRecord::Base#query_constraints
and composite keys are incompatible with ActiveStorage
#51127
Labels
ActiveRecord::Base#query_constraints
and composite keys are incompatible with ActiveStorage
#51127
Steps to reproduce
Expected behavior
Since ActiveStorage storage tables are not configurable, it should simply work. Attaching a file should result in an attached file.
Actual behavior
query_constraints
route results in an attempt to query non-existing columns onactive_storage_attachments
. Redefining relations on a model doesn't help, since inversebelong_to
association then attempts to compare two columns to one inActiveRecord::AutosaveAssociation#compute_primary_key
.Composite primary key route doesn't work, unless the key contains
:id
column.Notes
This is kind-of solvable by adding exttra columns to
active_storage_attachments
, but that can get out of hand real fast.Incidentally, allowing
belongs_to
to accept an arrayprimary_key
, would solve the problem by letting the record have a regularid
for use by ActiveSupport, but configure relations between models using composite keys. Right now, this route doesn't work due toActiveRecord::Reflection::BelongsToReflection#association_primary_key
transformingprimary_key
option withto_s
.System configuration
Rails version: 7.1.3
Ruby version: 3.3.0
The text was updated successfully, but these errors were encountered: