# Unable to retrieve data from a table in collection

**URL:** <https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840>\
**Category:** Help me!\
**Created:** [January 13, 2023, 2:26pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840 "2023-01-13T14:26:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuHue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/juhue/32/5609_2.png) [@JuHue](https://community.forestadmin.com/u/JuHue)\
**Post date:** [January 13, 2023, 2:26pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840/1 "2023-01-13T14:26:43Z")

</div>

## Feature(s) impacted

Inside the data tabs, we have several collections who all work beside one.

## Observed behavior

When Forest admin try to retrieve the data, he makes an API call to my local url [http://localhost:3000/forest/Product](http://localhost:3000/forest/Product). This call trigger a function inside my back which execute a sql command containing an error. This error is due to “LEFT OUTER JOIN” on an non existing column. (we have something like “LEFT OUTER JOIN Clients on Clients.product\_id = products.id”), here the product\_id inside clients doesn’t exist.

## Expected behavior

For all of my others collections everything is fine, but not the products collection.

## Failure Logs

the web console log display an error 500 after calling a GET request on the url [http://localhost:3000/forest/Product](http://localhost:3000/forest/Product)

the backend console display this error:

 ![Capture d’écran du 2023-01-13 15-16-53](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/c3d62cf827ac0bdec167eefd52823bbc8972ca23.png)  
 ![Capture d’écran du 2023-01-13 15-17-35](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/e/e197755ca8bfca7e20be34baaf8651351c4e27c1.png)  
 ![Capture d’écran du 2023-01-13 15-17-57](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/4/4ba871cf0912504e1075743fe728b56f1a2c5070.png)

## Context

- Project name: AB Tracking
- Team name: Operations
- Environment name: development
- Agent type & version: forest admin for Rails env (version 7.7.2)
- Recent changes made on your end if any: I’ve seen and removed product\_id in the Clients inside the forestadmin-schema.json

Moreover I’m using a docker container and after several tries I never could update the schema using the command forest schema:update. Note that the error was there before I tried to change the forestadmin-schema.json

Don’t hesitate to ask for deeper informations.

Regards,  
Julien

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [January 13, 2023, 3:19pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840/2 "2023-01-13T15:19:32Z")

</div>

Hello @JuHue and welcome to our community !

I am sorry to hear that you have issues, our rails agent will generate the queries based on the model you have defined, removing the fields directly in the .forestadmin-schema.json will not help you. If you are confortable with it you can share the models of your Client and Products classes.

Best regards,

Dogan

---

<div class="post-metadata">

**Author:** ![JuHue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/juhue/32/5609_2.png) [@JuHue](https://community.forestadmin.com/u/JuHue)\
**Post date:** [January 13, 2023, 3:42pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840/3 "2023-01-13T15:42:10Z")

</div>

Hello Dogan, thanks for the response !

Im sharing my models with you.

This my Client model:

 ![Capture d’écran du 2023-01-13 16-41-04](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/cc5edaf7bbfc6636e16c94e0f66e39b048aed95e.png)

And this is my products model:  
 ![Capture d’écran du 2023-01-13 16-41-48](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/1d7a3b69edbc9f0f25b509ab2113465bce194ffd.png)

Does it help you ?

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [January 13, 2023, 3:55pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840/4 "2023-01-13T15:55:56Z")

</div>

Yes thank you !

I noticed that you have set the relation “has\_one” to your client from the Product model. Based on the rails [documentation on associations](https://guides.rubyonrails.org/association_basics.html#the-has-one-association) when using a “has\_one” association, the table “client” would be the one owning the association id. So the generated query does respect the type of association defined.

I don’t know how your database is structured, but if the association is owned by the “products” table via a “client\_id”, a better fitting association would be “belongs\_to” ([here is the documentation](https://guides.rubyonrails.org/association_basics.html#the-belongs-to-association)).

---

<div class="post-metadata">

**Author:** ![JuHue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/juhue/32/5609_2.png) [@JuHue](https://community.forestadmin.com/u/JuHue)\
**Post date:** [January 13, 2023, 4:05pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840/5 "2023-01-13T16:05:04Z")

</div>

Indeed, this was my error. Thank you very much

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [January 13, 2023, 4:11pm UTC](https://community.forestadmin.com/t/unable-to-retrieve-data-from-a-table-in-collection/5840/6 "2023-01-13T16:11:39Z")

</div>

I am happy to have been able to help ! Feel free to create a new topic if you encounter issues.  
I will mark this as solved.

Have a nice week-end ! 🙂
