grand-parent、parent、childの3つのモデル:Organization
,Category
、Post
があります。コレクションとgrand-parentの両方で.whereを使用してスコープを作成
私は、私のPost
モデルにスコープを作成しようとして渡されたコレクションの最初のwhere
を使用して、壮大な親にしています:
scope :ready, -> {
where("next_setup_at < ?", DateTime.current)
.joins(category: :organization)
.where("organizations.active = ?", true)
}
しかし、Postgresは私にエラー投げている:
をActiveRecord::StatementInvalid: PG::AmbiguousColumn: ERROR: column reference "next_setup_at" is ambiguous LINE 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" = "categories"."organization_id" WHERE (next_setup_at < '2016-03-22 15:57:19.971887') AND (organizations.active = 't')
'WHERE'方法は、関係者、テーブル名を使用していません名。 – MrYoshiji
ありがとう!素敵なつか:) –