# Belongs\_to optional breaks the display of collection

**URL:** <https://community.forestadmin.com/t/belongs-to-optional-breaks-the-display-of-collection/6277>\
**Category:** Help me!\
**Created:** [May 9, 2023, 6:03pm UTC](https://community.forestadmin.com/t/belongs-to-optional-breaks-the-display-of-collection/6277 "2023-05-09T18:03:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AugustinBarbe](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/augustinbarbe/32/4909_2.png) [@AugustinBarbe](https://community.forestadmin.com/u/AugustinBarbe)\
**Post date:** [May 9, 2023, 6:03pm UTC](https://community.forestadmin.com/t/belongs-to-optional-breaks-the-display-of-collection/6277/1 "2023-05-09T18:03:43Z")

</div>

Hello everyone !

I have the following model :

```ruby
class Participant
   belongs_to :client, optional: true
end

class Client
  has_many :participants
end

```

as a `participant` can

Displaying the collection results in the error " The request to your server either failed or returned invalid data."  
Looking at the stacktrace, it seems that the forest\_liana tries to order the `participant` table with the client id, even though it is an optional relationship

Participant Load (0.9ms) SELECT “participants”.\* FROM “participants” ORDER BY “clients”.“id” DESC LIMIT $1 OFFSET $2 [[“LIMIT”, 100], [“OFFSET”, 0]]  
[2023-05-09 17:49:17] Forest 🌳🌳🌳 Records Index error: PG::UndefinedTable: ERROR: missing FROM-clause entry for table “clients”  
LINE 1: …ECT “participants”.\* FROM “participants” ORDER BY “clients”…

The request sent by the dashboard is the following :

`forest/Participant?timezone=America%2FMerida&fields%5BParticipant%5D=id%2Cfirstname%2Clastname&page%5Bnumber%5D=1&page%5Bsize%5D=100&sort=-client.id`

I have the following version for the forest\_liana gem : 8.0.6 and using rails 6.1.7.3  
Thanks for your help

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [May 10, 2023, 7:32am UTC](https://community.forestadmin.com/t/belongs-to-optional-breaks-the-display-of-collection/6277/2 "2023-05-10T07:32:19Z")

</div>

Hello,  
I think your collection settings are configured to sort on the `client.id` field by default. A solution is to change this parameter to another field.  
To do this, you can go to the parameters of your collection by following this [tutorial](https://docs.forestadmin.com/user-guide/collections/manage-your-collection-settings#access-your-collection-settings).

---

<div class="post-metadata">

**Author:** ![AugustinBarbe](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/augustinbarbe/32/4909_2.png) [@AugustinBarbe](https://community.forestadmin.com/u/AugustinBarbe)\
**Post date:** [May 10, 2023, 3:05pm UTC](https://community.forestadmin.com/t/belongs-to-optional-breaks-the-display-of-collection/6277/3 "2023-05-10T15:05:10Z")

</div>

Spot on, thank you for the quick answer !
