Smart Relationship with Smart Collection

Feature(s) impacted

Smart Relationship

Observed behavior

I just created a Smart Collection “lcbft-scores” and I’m trying to set up a Smart Relationship with a “normal” collection, the “users” db table.
The column of the relation remains empty.
Here is the code of the field declaration :

    {
      field: 'user',
      type: 'String',
      reference: 'User',
      get: (line) => {
        if (!line.id) return null
        return db.User.findByPk(line.id)
      },
    }

The “line.id” is correctly filled with the user id.
I don’t know if i need to fill a “user” attribute in the code of the route that returns the values for the smart collection, in the “user” field I tried to pass the id, the whole user object, and null, but the “user” column is still empty in the displayed table.
I noticed by adding logs that the “get” function of the declaration is never called.

(If you test on our environment, it’s normal if the smart collection returns an empty line, you need to enter a user id in the search field so that it returns the line for this user. You can use the id “3381” to get values).

Also, i wonder if it’s possible to add a link to the smart collection in the “users” summary view, like for any 1:1 relationship. On the fields config page, the “user” appears in the list of the relationships of the smart collection, but the “lcbft-scores” smart collection doesn’t appear in the list of the user relationships. I didn’t try to declare the relationship in the “user” model, i don’t think it would work since “lcbft-scores” is not an actual db model.
Is there a way to do this ?

Thanks in advance

Context

  • Project name: ma-domiciliation
  • Team name: Admin et dev
  • Environment name: Staging-dev
  • Agent technology: node
  • Agent (forest package) name & version: “forest-express-sequelize”: “~9.3.10”,
  • Database type: postgres

Hello,
As you said, you need to create a smart relationship (documentation).

In the reference attribute, your are probably missing the id:

reference: 'User' ====> reference: 'user.id'

After that, a link will be automatically added in the summary view. You can visit the documentation to help you.

I hope my message will help you :pray:
Tell me if you are still blocked.

For reference you can follow this :point_down::

Hello, all! This is my first post after just joining this discussion, so please forgive me and provide kind assistance if I have posted to the wrong subsection!

I am new here but a real enthusiast and loving this community so far. I have a background in teaching coding and in education and feel I could help with documentation, at least for starters.

Thank you.
Dann

1 Like