feat(schema): expose foreign_key_type_field on polymorphic relation#316
Merged
christophebrun-forest merged 1 commit intoJun 10, 2026
Merged
Conversation
Expose the discriminator column name (e.g. "addressable_type") as metadata of the PolymorphicManyToOne relation in the emitted schema, alongside polymorphic_referenced_models, so the Forest query executor can resolve which model a polymorphic record targets. The raw _id/_type columns remain hidden from the frontend; only the NAME of the _type column is exposed as relation metadata. Ref: PRD-493 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
forest-bot
added a commit
that referenced
this pull request
Jun 10, 2026
# [1.32.0](v1.31.0...v1.32.0) (2026-06-10) ### Features * **schema:** expose foreign_key_type_field on polymorphic relation ([#316](#316)) ([157af7e](157af7e))
Member
|
🎉 This PR is included in version 1.32.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
In the schema emitted for
PolymorphicManyToOnerelations (belongs_to ..., polymorphic: true), we already exposed the list of target models viapolymorphic_referenced_models, but not the name of the discriminator column (the_type, e.g.addressable_type). As a result, the Forest query executor could not resolve which model a polymorphic record targets.Change
On the polymorphic relation field of the emitted schema, expose the discriminator column name as metadata, next to
polymorphic_referenced_models:polymorphic_referenced_models): snake_caseforeign_key_type_field.SchemaEmitterserializes the collection hash as-is), so nothing to add there._id/_typecolumns remain hidden from the frontend — only the name of the_typecolumn is exposed as relation metadata; behaviour unchanged.Tests
generator_field_polymorphic_spec.rbto assertforeign_key_type_field: 'addressable_type'.utils/schema/suite: 199 examples, 0 failures.Ref
🤖 Generated with Claude Code
Note
Expose
foreign_key_type_fieldin polymorphic relation field schemaAdds
foreign_key_type_fieldto the hash returned byGeneratorField.build_column_schemafor polymorphic foreign key columns, populated fromrelation.foreign_key_type_field. The spec in generator_field_polymorphic_spec.rb is updated to assert the new field is present with the correct value.Macroscope summarized 2d13057.