Polymorphic fields with issues

Feature(s) impacted

Some polymorphic fields not displayed correctly.

Observed behavior

Most of the polymorphic fields in our db are now displayed correctly using Polymorphic BelongsTo Typeahead, but some are not.
When trying to edit them that option does note exist.

class Example < ApplicationRecord
  belongs_to :mapped_to, polymorphic: true, optional: true
  belongs_to :something, optional: true
  belongs_to :owner, class_name: 'Something'
def Something < Application Record
   has_many :examples, inverse_of: :owner, foreign_key: :owner_id, dependent: :destroy
   # no reference to the actual polymorphic field - maybe that's the issue?
  "field": "mapped_to",
  "type": "Number",
  "default_value": null,
  "enums": null,
  "integration": null,
  "is_filterable": false,
  "is_read_only": false,
  "is_required": false,
  "is_sortable": true,
  "is_virtual": false,
  "reference": "mapped_to.id",
  "inverse_of": "tpa_mapping",
  "relationship": "BelongsTo",
  "widget": null,
  "validations": [],
  "polymorphic_referenced_models": []

Is there a way to force them to be polymorphic in the UI?
Also side question: How does forest determine the polymorphic type options related to a specific field? Is there a way to manually control this?

Expected behavior

Being able to set the field as polymorphic


Recently upgraded forest_liana from 8.0.13 to 9.1.0
Database: postgres (PostgreSQL) 16.2
Rails 7.0.8
Ruby 3.2.3

  • Project name: Hint Health
  • Team name: Hint Health
  • Environment name: Production

Hello @Santiago_Herrero

Welcome on the ForestAdmin community

Can you please add this information so we can better help you ?

  • Project name: …
  • Team name: …
  • Environment name: …

Can you please also share with us you models declarations for both part of the relation ?

Thanks @nbouliol - Updated my original message with the requested info

1 Like

Hi @Santiago_Herrero,

Exactly, you need to add the reference to the polymorphic relationship.
Unfortunately, there is currently no way of controlling this manually.

1 Like