PG :: UndefinedTable:错误:表"团队"缺少FROM子句条目

时间:2017-08-17 21:25:33

标签: ruby-on-rails ruby postgresql

尝试按关联表格排序查询时出现以下错误" name"属性。

错误

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

查询

: SELECT "team_seasons"."id" AS t0_r0, "team_seasons"."season_id" AS t0_r1, "team_seasons"."team_id" AS t0_r2, "team_seasons"."created_at" AS t0_r3, "team_seasons"."updated_at" AS t0_r4, "team_seasons"."points" AS t0_r5, "team_seasons"."goals_for" AS t0_r6, "team_seasons"."goals_against" AS t0_r7, "team_seasons"."games_played" AS t0_r8, "teams"."id" AS t1_r0, "teams"."name" AS t1_r1, "teams"."city" AS t1_r2, "teams"."created_at" AS t1_r3, "teams"."updated_at" AS t1_r4 FROM "team_seasons" LEFT OUTER JOIN "teams" ON "teams"."id" = "team_seasons"."team_id" WHERE "team_seasons"."season_id" = 1  ORDER BY team.name

SeasonsController.rb

class SeasonsController < ApplicationController
load_and_authorize_resource

def show
    @season = Season.find(params[:id])
    @teamseasons = TeamSeason.where(season: @season).includes(:team).order("team.name")
end

通过团队季度记录中的属性删除订单或排序不会产生错误,因此我知道它与相关记录的排序有关。我认为包括它是我需要做的所有事情,但显然它不起作用。任何帮助深表感谢。

1 个答案:

答案 0 :(得分:0)

尝试将team.name更改为teams.name s

TeamSeason.where(season: @season).includes(:team).order("team.name")