Polymorphic tables

Feature(s) impacted

In my development environment, I am implementing the EmailDelivery collection. In my Rails app, the “sent_to” column is polymorphic and either belongs to a Candidate or a Recruiter.

Observed behavior

The problem in Forest Admin is that I cannot a make the data clickable in that column so that it redirect to the correct Forest Admin page of the recruiter or candidate.

Expected behavior

I would like to have a column sent_to in my Email Delivery table in Forest Admin which would contain a clickable Candidate or Recruiter.

Failure Logs

Context

  • Project name: Squarehub
  • Team name: Squarehub
  • Environment name: Automations
  • Agent (forest package) name & version: …
  • Database type: …
  • Recent changes made on your end if any: …

Hey @samrozen :wave:

From what I understood of your use case, maybe a smart field on the Email delivery table would help.

You could generate the associated link to a Candidate or a Recruiter in this smart field, depending on your polymorphic association ?

Let me know if that helps.

I have inserted a smart field like that:

class Forest::EmailDelivery
  include ::ForestLiana::Collection

  collection :EmailDelivery

  field :sent_to, type: "String", is_filterable: true do
    "#{object.sent_to.first_name} #{object.sent_to.last_name}"
  end
end

But I don’t find how to generate the associated link for the object.sent_to. Also, I don’t have the BelongsTo Typeahead option showing up in the Forest Admin fields settings.

Sadly, generating a link will be a manual process. As of now, Forest Admin doesn’t really handle polymorphic association, so the idea above is mainly a workaround to make something work.

Creating a smart collection with all Recruiter and Candidate in the same collection with an enum value to distinguish between both could also be a solution.

I’ll push your thread as a feedback on our product board.