相关疑难解决方法(0)

Rails has_many:通过PG ::错误:错误:列引用"id"是模糊错误

我是rails的新手,我一直在试图获得两个has_many:虽然关系可以解决(而不是像本帖所解释的那样使用has_and_belongs_to_many http://blog.flatironschool.com/post/35346328762/why-you -dont-need-have-and-belongs-to-many)但现在遇到Postgres错误:

PG::Error: ERROR:  column reference "id" is ambiguous
LINE 1: ...on_id" IS NULL AND "components"."id" = 1 ORDER BY id ASC LIM...
                                                             ^
: SELECT  1 AS one FROM "components" INNER JOIN "collection_components" ON "components"."id" = "collection_components"."component_id" WHERE "collection_components"."collection_id" IS NULL AND "components"."id" = 1 ORDER BY id ASC LIMIT 1
  Rendered collections/_form.html.haml (117.0ms)
  Rendered collections/new.html.haml within layouts/application (143.5ms)
Completed 500 Internal Server Error in 164ms

ActiveRecord::StatementInvalid - PG::Error: ERROR:  column reference "id" is ambiguous
LINE 1: …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails has-many-through

7
推荐指数
1
解决办法
5620
查看次数