I have a event model. Events can have parent events, set from a column in the model (parent_event_id). I need to be able to do has_many :event
on the model, so I can just do, for example, event.child_event
or event.parent_event
. But my googling hasn't worked out that well.
My Model:
class Event < ActiveRecord::Base
attr_accessible :days_before, :event_name, :event_date, :list_id, :recipient_email, :recipient_name, :parent_event_id, :is_deleted, :user_id
belongs_to :user
has_many :event_email
has_many :event
end
My Schema:
create_table "events", :force => true do |t|
t.datetime "event_date"
t.integer "days_before"
t.string "recipient_email"
t.integer "list_id"
t.string "recipient_name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.string "event_name"
t.integer "parent_event_id"
t.boolean "is_deleted", :default => false
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…