0
votes

I got the following error:

PG::UndefinedTable: ERROR: missing FROM-clause entry for table "clients".

This occurs when I try to execute the following query:

SELECT  "folders".* FROM "folders" WHERE (clients.name ilike '%aleena%')  ORDER BY clients.name LIMIT 10):

The following code is used for select:

  def search_folders
    Folder.where('clients.name ilike :search', search: "%#{@params[:s]}%")
          .references(:clients)
          .order('clients.name')
          .limit(@params[:per] || 10)
  end
1
Do you have folders table in your db? Did you create and run your migrations? - Marek Lipka
Yes I have folders table. - geethujoseph
You are using :clients table in the where clause but it doesn't present in the :from - Alexander Shlenchack
I use above code for this, please check it: - geethujoseph
Like @AlexanderShlenchack wrote, you try to fetch folders, but you're using clients columns in your where clause. - Marek Lipka

1 Answers

0
votes

You should join your clients table in your query:

Folder.joins(:client)
      .where('clients.name ilike :search', search: "%#{@params[:s]}%")
      .references(:clients)
      .order('clients.name')
      .limit(@params[:per] || 10)