Unable to display fields generated by afterFind Sequelize Hook in Relationship

Feature(s) impacted

I have this data model:
Shareholder: 1--N :ShareholderDocument: 1--1 :Document

ShareholderDocument only contains an id, shareholderId and documentId, while Document model has more information like contentType, documentType, status etc.

In my view Shareholder, I would to see its list of documents with all the infos (contentType, documentType, status etc).
I created in my sequelize ShareholderDocumentModel a hook afterFind to retrieve these fields:

Observed behavior

When I go to my dashboard, on a Shareholder, I see the following:


You can see on the bottom right that all fields related to Document are blank (contentType, documentType, status etc). I guess this is due to this issue from Sequelize

Expected behavior

I am expecting to see all fields filled like this (caught from the ShareholderDocument view, where all fields are correctly fetched -given its not fetched using a relationship (cf issue mentionned above)-)

Context

The environnement is local

Strategy

I understand given the issue mntionned above, what I want to do using sequelize hooks might be impossible.
My question instead would be:

  • Should I use Forest Hooks ?
  • Should I use smartFields ?
  • Should I use a smartRelationship with DocumentModel directly ? (we would like to avoid it)

Thank you for your help :slight_smile:

Hello @paulclavier,

Thank you for your message :raised_hands:

After having reading your use case, I have a small question: why not defining a new association in your Shareholder’s model that refers directly to Document through the join table (ShareholderDocument)?
Did you try that (here is some Sequelize documentation about it)?

If it works for you, in the UI, in the Shareholder related data you could just display the Documents and hide ShareholderDocuments.

Let me know!
Thanks.

Hey @adriguy ,

Thank you for your reply.
We did consider this choice at first but we have ShareholderDocument and also multiple tables for different document owners like OtherTypeOfOwnerDocument let’s say.
We want to maybe apply different business rules in the models for each type of owner.

However we did manage to cope with our issue :slight_smile:
We used Sequelize hooks afterFind to enrich our ShareholderDocument with Document information.
Then we defined a smartRelationship between our Shareholder and ShareholderDocument (Sequelize fetching directly thus with hooks activated)
It works nicely.

1 Like