Ich habe ein Consultation
Modell, das eine post_consultant
und eine consultant
hat. Sowohl post_consultant
als auch consultant
sind Verweise auf das Modell Employee
. So könnte man sagen:Rails Association: 2 Vorkommen des gleichen Modells
Modell
Class Consultation < ActiveRecord::Base
has_one :employee # for consultant
has_one :employee # for post_consultant
end
Migration
create_table "consultations", force: :cascade do |t|
t.boolean "showed_up"
t.boolean "signed_up"
t.integer "client_id"
t.integer "consultant_id"
t.integer "post_consultant_id"
end
Wie soll ich das schreiben soll?
Correct Modell:
class Consultation < ActiveRecord::Base
belongs_to :consultant, class_name: "Employee", foreign_key: "consultant_id"
belongs_to :post_consultant, class_name: "Employee", foreign_key: "post_consultant_id"
end
post_consultant und berater ist ein modell? – krishnar
Welcher Fremdschlüssel für post_consultant und Berater? – krishnar
nur Mitarbeiter ist ein Modell –