Ich habe eine STI-Tabelle "Parteien" wie folgt:Rails belongs_to STI Tabelle mit Rahmen
# app/models/party.rb
class Party < ApplicationRecord
has_many :party_contacts
scope :vendors, -> { where(type: 'Party::Vendor') }
scope :customers, -> { where(type: 'Party::Customer') }
end
# app/models/party/vendor.rb
class Party::Vendor < Party
end
# app/models/party/customer.rb
class Party::Customer < Party
end
Und "party_contacts" Tabelle wie folgt:
class PartyContact < ApplicationRecord
belongs_to :party
scope :of_vendors, -> {# fetch all contacts belongs to all vendors logic }
scope :of_customers, -> {# fetch all contacts belongs to all customers logic }
end
Ich möchte Abfrage machen auf " party_contacts ", um eine Liste aller Händler/Kundenkontakte zu erhalten. Wie kann ich den Umfang für "party_contacts" schreiben (oder sollte es im übergeordneten Modell sein)?
Ich versuche folgende Bereiche:
scope :of_vendors, -> { joins(:party).includes(:party).where(party: { type: "Party::Vendor" }) }
scope :of_customers, -> { joins(:party).includes(:party).where(party: { type: "Party::Customer" }) }
Aber bekommen Fehler:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "party"
LINE 1: ...parties"."id" = "party_contacts"."party_id" WHERE "party"."t...
'wo (Partei:' sollte – Swards