# ManyToOne relation on same Table make Forest crash on row selection

**URL:** <https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650>\
**Category:** Help me!\
**Tags:** dashboard\
**Created:** [September 11, 2023, 2:02pm UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650 "2023-09-11T14:02:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ludovic\_Lacuska](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ludovic_lacuska/32/6456_2.png) [@Ludovic\_Lacuska](https://community.forestadmin.com/u/Ludovic_Lacuska)\
**Post date:** [September 11, 2023, 2:02pm UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/1 "2023-09-11T14:02:42Z")

</div>

## Feature(s) impacted

In Forest dashboard, at this url :  
[https://app.forestadmin.com/mycompany/Production/Operations/data/user/index](https://app.forestadmin.com/mycompany/Production/Operations/data/user/index)  
on the table row list, the click on a row should redirect to the detailed view of this row

## Observed behavior

In Forest dashboard, at this url :  
[https://app.forestadmin.com/mycompany/Production/Operations/data/user/index](https://app.forestadmin.com/mycompany/Production/Operations/data/user/index)  
on the table row list, the click on a row in a table make application crash

## Expected behavior

Display details of clicked row

## Failure Logs

Dashboard error :  
Cannot reach your data  
Your server may be down or your database connection broken.  
Please check your server logs for more information. If the error persists, please [let us know](https://community.forestadmin.com/).

browser error :  
[forest] :feuillu::feuillu::feuillu: Unexpected error in details view:

## Context

- Project name: …
- Team name: …
- Environment name: …
- Agent (forest package) name & version:  
“@forestadmin/agent”: “^1.0.0-beta.41”,  
“@forestadmin/datasource-sql”: “^1.0.0-beta.39”,
- Database type: PosgreSql
- Recent changes made on your end if any: add relation OneToMany on User table targeting the same table. Before this change, the dashboard did not crash

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [September 11, 2023, 2:32pm UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/2 "2023-09-11T14:32:24Z")

</div>

Hello @Ludovic_Lacuska,

Thanks for reaching out.

In order to help you out, could you please detail a little bit more:

- In your case, one User has many other Users? What’s your use case?
- Do you have any error in your agent console?
- Could you share more details of the browser console error?

Thank you!

---

<div class="post-metadata">

**Author:** ![Ludovic\_Lacuska](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ludovic_lacuska/32/6456_2.png) [@Ludovic\_Lacuska](https://community.forestadmin.com/u/Ludovic_Lacuska)\
**Post date:** [September 12, 2023, 1:30pm UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/3 "2023-09-12T13:30:55Z")

</div>

Hello,

Thanks for you fast reply.

This is how my users are linked :

```javascript
class UserEntity {
  @ManyToOne(() => UserEntity, (user) => user.refferingUsers, {
      nullable: true,
    })
  @JoinColumn()
  refferedBy: UserEntity;

  @OneToMany(() => UserEntity, (user) => user.refferedBy)
  refferingUsers: UserEntity[];
}

```

I need to know if a user has been referred by another one (like sponsorship)

How can I access the agent console you’re talking about?

The browser error looks like this :

```javascript
Message : Ember Data Request GET api-dot-MyCompany-production.oa.r.appspot.com/forest/user/3225 returned a 500\nPayload (application/json; charset=utf-8)\n[object Object]

Stack : Error: Ember Data Request GET api-dot-MyCompany-production.oa.r.appspot.com/forest/user/3225 returned a 500\nPayload (application/json; charset=utf-8)\n[object Object]\n at n.i (app.forestadmin.com/assets/vendor-d090e5c62b54db7a841f6a16ca9727ed.js:89:229557)\n at new n (app.forestadmin.com/assets/vendor-d090e5c62b54db7a841f6a16ca9727ed.js:89:230315)\n at b.handleResponse (app.forestadmin.com/assets/vendor-d090e5c62b54db7a841f6a16ca9727ed.js:89:236787)\n   
[[Prototype]]
: 
Error

```

And I have a 500 error on Get at this url :  
[api-dot-myCompany-production.oa.r.appspot.com/forest/user/3225?timezone=Europe%2FParis](http://api-dot-myCompany-production.oa.r.appspot.com/forest/user/3225?timezone=Europe%2FParis)

Thanks !

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [September 13, 2023, 6:31am UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/5 "2023-09-13T06:31:27Z")

</div>

Hello @Ludovic_Lacuska,

Can you please share with us the structure around this table `User` please? It’ll help us reproduce the issue. I don’t need all the tables nor all the columns : I just need a description of the ones involved in the issue.

In addition to that, I can see that you’re using a very old version of the packages : can you please update to the latest? The packages you’re using are beta versions. The recent versions are compatible with this one, so the jump won’t be difficult.

Thanks

---

<div class="post-metadata">

**Author:** ![Ludovic\_Lacuska](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ludovic_lacuska/32/6456_2.png) [@Ludovic\_Lacuska](https://community.forestadmin.com/u/Ludovic_Lacuska)\
**Post date:** [September 13, 2023, 3:45pm UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/6 "2023-09-13T15:45:25Z")

</div>

Hello,

We tried to update our packages to this versions :  
“@forestadmin/agent”: “^1.28.1”,  
“@forestadmin/datasource-sql”: “^1.7.26”,

We had to install the package  
“@types/koa\_\_router”: “^12.0.0”, in order to make the build works

We change the createAgent method from

```javascript
const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    agentUrl: process.env.FOREST_AGENT_URL,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.NODE_ENV === "production",
    clientId: process.env.FOREST_CLIENT_ID,
  }).addDataSource(createSqlDataSource(process.env.DATABASE_URL));

```

To this

```javascript
const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    forestServerUrl: process.env.FOREST_AGENT_URL,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.NODE_ENV === "production",
  }).addDataSource(createSqlDataSource(process.env.DATABASE_URL));

```

We don’t know how to use the FOREST\_CLIENT\_ID.

Deploying this we have an issue on Forest console.

## Agent unreachable

‘[https://app.forestadmin.com](https://app.forestadmin.com)’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

On the app we use nest.js and we already have enable Cors

Concerning the User Entity the model is quite big but we had no issues before adding this relation on himself.

Thanks

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [September 14, 2023, 6:26am UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/7 "2023-09-14T06:26:32Z")

</div>

Ok, this is another problem.

Can you please get the response from the agent to the `OPTIONS` request? I need the headers from this response.

You can remove the property `forestServerUrl` which won’t be useful in your case.

---

<div class="post-metadata">

**Author:** ![Ludovic\_Lacuska](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ludovic_lacuska/32/6456_2.png) [@Ludovic\_Lacuska](https://community.forestadmin.com/u/Ludovic_Lacuska)\
**Post date:** [September 14, 2023, 9:24am UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/8 "2023-09-14T09:24:36Z")

</div>

Hello,

Whe have 2 OPTIONS requests

The first request response header looks like this :

```bash
HTTP/1.1 204 No Content
Server: Cowboy
Connection: keep-alive
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
X-Dns-Prefetch-Control: off
Expect-Ct: max-age=0
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
Origin-Agent-Cluster: ?1
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: no-referrer
X-Xss-Protection: 0
Access-Control-Allow-Origin: https://app.forestadmin.com
Vary: Origin, Access-Control-Request-Headers
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Access-Control-Allow-Headers: authorization,content-type,forest-environment-id,forest-project-id,forest-rendering-id,forest-team-id
Access-Control-Max-Age: 86400
Access-Control-Expose-Headers: Content-Disposition
Content-Length: 0
Date: Thu, 14 Sep 2023 09:05:24 GMT
Via: 1.1 vegur

```

The request header :

```bash
OPTIONS /api/renderings/mycompany/Staging/Operations HTTP/1.1
Host: api.forestadmin.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization,content-type,forest-environment-id,forest-project-id,forest-rendering-id,forest-team-id
Referer: https://app.forestadmin.com/
Origin: https://app.forestadmin.com
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site

```

 ![Capture d’écran 2023-09-14 à 11.21.47](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/3/36ba1516cef4bb7088e65675677346dc02d977bb.png)

The second one response header :

```bash
HTTP/2 200 OK
content-type: application/json
vary: Accept-Encoding
x-powered-by: Express
content-encoding: gzip
x-cloud-trace-context: 354771bfdc2443edcee13e0d29dd78d8;o=1
date: Thu, 14 Sep 2023 09:05:24 GMT
server: Google Frontend
cache-control: private
content-length: 58
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
X-Firefox-Spdy: h2

```

The request header

```bash
OPTIONS /forest/authentication HTTP/2
Host: api-dot-mycompany.ew.r.appspot.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Referer: https://app.forestadmin.com/
Origin: https://app.forestadmin.com
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site

```

 ![Capture d’écran 2023-09-14 à 11.21.37](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/4/493b7ff489f3602a09fc105db7427d05bebd843d.png)

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [September 14, 2023, 2:46pm UTC](https://community.forestadmin.com/t/manytoone-relation-on-same-table-make-forest-crash-on-row-selection/6650/9 "2023-09-14T14:46:50Z")

</div>

Thank you,

The first request is made to our servers and the response is correct.

The second request is made to your agent, and we can see that the response is not. We can see that Google Frontend’s servers instead of the agent.

I think that there is a problem with the deployment on your servers. The agent is not called by the server on the URL that is configured.

For info, if you open a browser and access to `[your-agent-url]/forest` it should answer a basic message such as

```json
{"error":null,"message":"Agent is running"}

```

If you get an error from google instead, it means that something is misconfigured in the deployment.
