【发布时间】:2016-03-22 16:08:09
【问题描述】:
我有三个具有祖父母、父母、子女关系的模型:Organization、Category、Post。
我正在尝试在我的 Post 模型中创建一个范围,首先在传递的集合上使用 where,然后在祖父母上使用:
scope :ready, -> {
where("next_setup_at < ?", DateTime.current)
.joins(category: :organization)
.where("organizations.active = ?", true)
}
但是 Postgres 给我一个错误:
ActiveRecord::StatementInvalid: PG::AmbiguousColumn: 错误: 列引用“next_setup_at”不明确 第 1 行:...zations"."id" = "categories"."organization_id" WHERE (next_setup... ^
: SELECT "posts".* FROM "posts" INNER JOIN "categories" ON "categories"."id" = "posts"."category_id" INNER JOIN "organizations" ON "organizations"."id" = "类别"."organization_id" WHERE (next_setup_at
【问题讨论】:
标签: ruby-on-rails postgresql ruby-on-rails-5