# Migration to \`@forestadmin/agent\` - The new agent tries to load fields / smart fields for relationships that are not defined in the record details page

**URL:** <https://community.forestadmin.com/t/migration-to-forestadmin-agent-the-new-agent-tries-to-load-fields-smart-fields-for-relationships-that-are-not-defined-in-the-record-details-page/7413>\
**Category:** Help me!\
**Tags:** smart-field, migration-to-agentv2, relationship\
**Created:** [August 22, 2024, 11:05am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-the-new-agent-tries-to-load-fields-smart-fields-for-relationships-that-are-not-defined-in-the-record-details-page/7413 "2024-08-22T11:05:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/matteo/32/75_2.png) [@Matteo](https://community.forestadmin.com/u/Matteo)\
**Post date:** [August 22, 2024, 11:05am UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-the-new-agent-tries-to-load-fields-smart-fields-for-relationships-that-are-not-defined-in-the-record-details-page/7413/1 "2024-08-22T11:05:24Z")

</div>

We’re migrating from `forest-express-sequelize` to `@forestadmin/agent`.

The new agent tries to load fields / smart fields for relationships that are not defined in the record details page.

While navigating on the list view nothing happens, but if I navigate to the record details view (clicking on a single record) the agent tries to load smart fields even if the linked relationship is not defined.

In the list view the `getValues` is not called at all in the smart fields of the undefined relationship’s collection, but in the details view it is called passing `[{}]` as value for the `records` parameter, which causes many problems.

e.g. In the list view everything works, in the details view the record without the boat defined returns the error.

 ![image (41)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/250fed5c70f1f388f76cdc3dc6a290f1b6c3b23b.png)

![image (42)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/e/e732505afd4a62c40509e266fdd2882cc6100e23.png)

 ![image (43)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/53cd7ba6753caf8f9a6e9f0d73c721bc088d978a.png)

As a workaround we’ve had to add this check to every `getValues` .

![image (44)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/d/dde7449753b0df58fdce77d0aa60f15171c3ad76.png)

How to make this work correctly, without having to check it on our side?!?

Here is the “meta” section of the forest admin schema file:

```javascript
  {
    "liana": "forest-nodejs-agent",
    "liana_version": "1.41.7",
    "liana_features": null,
    "stack": {"engine": "nodejs", "engine_version": "20.11.1"}
  }

```

and from `package.json`:

```javascript
"sequelize": "^6.28.0"

```

cc @julien.jolles

Thank you  
Matteo

---

<div class="post-metadata">

**Author:** ![Enki](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/enki/32/6004_2.png) [@Enki](https://community.forestadmin.com/u/Enki)\
**Post date:** [August 26, 2024, 3:41pm UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-the-new-agent-tries-to-load-fields-smart-fields-for-relationships-that-are-not-defined-in-the-record-details-page/7413/2 "2024-08-26T15:41:22Z")

</div>

Hello @Matteo ,

Can you share a bit more of your agent’s code ?  
I cannot reproduce your issue and don’t understand where could the blank records come from.

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [August 27, 2024, 3:21pm UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-the-new-agent-tries-to-load-fields-smart-fields-for-relationships-that-are-not-defined-in-the-record-details-page/7413/3 "2024-08-27T15:21:34Z")

</div>

This is the expected behavior - Even on null relation, we’ll try to compute the potential list of smart fields on an empty record.  
This behavior was backported from v1 as some existing users are using it - but we may be lacking a bit of documentation on this one - I’ll file a ticket right away.

The general rule of thumbs regarding field computation is that `dependencies` will not always be provided - and this needs to be manually checked on your end.

A potential solution we use to deal with this is the following:

```javascript
function areDependenciesDefined(deps: string[], record: Record<string, any>): Boolean {
  return deps.every(dep => {
    if (dep.includes(':')) {
      const v = dep.split(':').reduce((acc, d) => { if(!acc) return; return acc[d]; }, record);
      return !!v;
    } else {
      return !!record[dep];
    }
  });
}

const myFieldDependencies = ['field1', 'field2'];

// ...
dependencies: myFieldDependencies
getValues: (records, context) => {
    return records.map(record => {
        if(areDependenciesDefined(myActionDependencies, record)) return null;
        // Do your actual dependency computation
    });
  }
}

```

Obvious it can be a bit more complex than this, especially when dealing with an API where you would not be able to iterate over the records, but the general idea is the same.

To give a bit more context:

- It works on the table view most likely because your `referenceField` is able to be computed on `null` value - And the associated record embed a projection asking only for this `referenceField`.
- It doesn’t in the record details because no projection is sent - Thus the full record needs to be recovered just in case the `referenceField` is actually a computed one.

Let me know if that helps 🙏

---

<div class="post-metadata">

**Author:** ![Matteo](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/matteo/32/75_2.png) [@Matteo](https://community.forestadmin.com/u/Matteo)\
**Post date:** [August 28, 2024, 1:14pm UTC](https://community.forestadmin.com/t/migration-to-forestadmin-agent-the-new-agent-tries-to-load-fields-smart-fields-for-relationships-that-are-not-defined-in-the-record-details-page/7413/5 "2024-08-28T13:14:08Z")

</div>

Thank you @anon39848301  
If this is the intended behaviour of the new agent we’re ok in managing this case on our side 👍 as you suggest.

Thank you very much.  
Matteo
