Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails PG::UndefinedTable:错误:表“的子句条目中缺少;团队“;_Ruby On Rails_Ruby_Postgresql - Fatal编程技术网

Ruby on rails PG::UndefinedTable:错误:表“的子句条目中缺少;团队“;

Ruby on rails PG::UndefinedTable:错误:表“的子句条目中缺少;团队“;,ruby-on-rails,ruby,postgresql,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

在尝试按关联表的“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
季节控制器.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
类季节控制器

删除teamseason记录上的订单或按属性排序不会产生错误,因此我知道这与相关记录的排序有关。我认为包括它是我需要做的全部,但显然它不起作用。非常感谢您的帮助

尝试将
team.name
更改为
teams.name
(记住s


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

尝试使用:
.includes(:team).references(:team).order(teams::name)
。在Rails 4+中,如果要在主SQL查询中使用包含关系(如
顺序
其中
选择
),您需要引用它,这样它将触发
左联接
,而不是执行两个单独的SQL查询。您是否有两个名为
团队
团队
的表?理想情况下,表名应以复数结尾。谢谢作为补充说明,我只有一个名为
teams
的表,没有
team
表。那么您可能有一个teamtable。如果数据库中没有名为
team
的表,PG将抛出不同的错误。