Ich habe drei Modelle mit Großeltern, Eltern, Kind Beziehung: Organization
, Category
, Post
.Erstelle Bereich mit .where auf beiden Sammlung und Großelternteil
Ich versuche, einen Rahmen in meinem Post
Modell zu erstellen, where
zunächst auf der übergebene Sammlung und anschließend auf den Großeltern:
scope :ready, -> {
where("next_setup_at < ?", DateTime.current)
.joins(category: :organization)
.where("organizations.active = ?", true)
}
Aber Postgres mir einen Fehler wirft:
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')
Die 'where' Methode verwendet den Namen der Tabelle, nicht die Beziehung des Name. – MrYoshiji
ye danke! Schön Gotcha :) –