PG :: UndefinedTable:错误:缺少表“clients”的FROM子句条目

时间:2015-12-18 07:28:16

标签: ruby-on-rails psql

我收到以下错误:

PG :: UndefinedTable:错误:缺少表“clients”的FROM子句条目。

当我尝试执行以下查询时会发生这种情况:

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

以下代码用于选择:

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

1 个答案:

答案 0 :(得分:0)

您应该在查询中加入Folder.joins(:client) .where('clients.name ilike :search', search: "%#{@params[:s]}%") .references(:clients) .order('clients.name') .limit(@params[:per] || 10) 表格:

{{1}}