Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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 整数的语法无效_Ruby On Rails_Postgresql_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 整数的语法无效

Ruby on rails 整数的语法无效,ruby-on-rails,postgresql,ruby-on-rails-4,Ruby On Rails,Postgresql,Ruby On Rails 4,我在尝试匹配查询us Postgres中的整数ID时收到此错误消息 PG::InvalidTextRepresentation:ERROR: invalid input syntax for integer: "matches.team_id" 我已经建立了联系 Stat belongs_to :player has_many :matches, foreign_key: 'match_id', primary_key: 'match_id' 匹配 has_many :stats has_m

我在尝试匹配查询us Postgres中的整数ID时收到此错误消息

PG::InvalidTextRepresentation:ERROR: invalid input syntax for integer: "matches.team_id"
我已经建立了联系

Stat

belongs_to :player
has_many :matches, foreign_key: 'match_id', primary_key: 'match_id'
匹配

has_many :stats
has_many :players, through: :stats
统计控制器

@player = Player.find(params[:id])    
@stats = Stat.where("player_id = ?", @player.id).joins(:matches)
.where('stats.team_id = ?', 'matches.team_id').select('SUM(stats.goals) AS goals')
我的比赛数据库有两个相同的
match\u id
行,当我总结球员目标时,它会找到球员目标,但在显示时会加倍
目标。所以我想,如果我的查询表明,只查找团队id相同的位置,那么每个
match\u id

匹配db

|id|match_id|team_id|total_score|
|10|  3433  |   1   |     3     |
|11|  3433  |   2   |     2     |
|id|match_id|team_id|player_id|goals|
|12|  3433  |   1   |   333   |  1  |
统计数据库

|id|match_id|team_id|total_score|
|10|  3433  |   1   |     3     |
|11|  3433  |   2   |     2     |
|id|match_id|team_id|player_id|goals|
|12|  3433  |   1   |   333   |  1  |
更改此项:

where('stats.team_id = ?', 'matches.team_id')
为此:

where('stats.team_id = matches.team_id')
当您对
使用替换时,您的意思是应该转义
的数据。它正在查看
“matches.team_id”
的类型,发现它是一个字符串,并将其用引号括起来

可能有一种方法可以在不需要自定义
where
子句的情况下进行连接,但问题的根源是字符串转义机制。

更改此方法:

where('stats.team_id = ?', 'matches.team_id')
为此:

where('stats.team_id = matches.team_id')
当您对
使用替换时,您的意思是应该转义
的数据。它正在查看
“matches.team_id”
的类型,发现它是一个字符串,并将其用引号括起来

可能有一种方法可以在不需要自定义
where
子句的情况下进行连接,但问题的根源是字符串转义机制