Belongs_to optional breaks the display of collection

Hello everyone !

I have the following model :

class Participant
   belongs_to :client, optional: true

class Client
  has_many :participants

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 :deciduous_tree::deciduous_tree::deciduous_tree: 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 :


I have the following version for the forest_liana gem : 8.0.6 and using rails
Thanks for your help

I think your collection settings are configured to sort on the 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.

Spot on, thank you for the quick answer !

1 Like