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 在rails中使用子查询_Ruby On Rails_Postgresql - Fatal编程技术网

Ruby on rails 在rails中使用子查询

Ruby on rails 在rails中使用子查询,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我有以下声明: @addresses = Location.joins(:Address).where('address.address_id = ?', Location.all.select('address_id').uniq.where(['delivery_id = ?', @delivery.id])).order('time') 它不工作,它在我的第一个where语句附近打印了一个错误 PG::SyntaxError: FEHLER: Syntaxfehler bei "SEL

我有以下声明:

@addresses = Location.joins(:Address).where('address.address_id = ?', Location.all.select('address_id').uniq.where(['delivery_id = ?', @delivery.id])).order('time')
它不工作,它在我的第一个where语句附近打印了一个错误

PG::SyntaxError: FEHLER:  Syntaxfehler bei "SELECT"
LINE 1: ... = "locations"."id" WHERE (addresses.address_id = SELECT DIS...
                                                         ^
: SELECT "locations".* FROM "locations" INNER JOIN "addresses" ON "addresses"."l
ocation_id" = "locations"."id" WHERE (addresses.address_id = SELECT DISTINCT add
ress_id FROM "locations"  WHERE (delivery_id = 6))  ORDER BY time
Completed 500 Internal Server Error in 4ms

假设
添加.address\u id
是正确的字段名,您还需要在
中使用
,而不是
=
<代码>=
需要一个结果,但您返回的多个结果需要在
中输入

where('address.address_id IN (?)',...