Get event object or ID from occurrence?

3 views
Skip to first unread message

dwayne

unread,
Oct 23, 2009, 5:17:44 PM10/23/09
to RiCal
Hi guys:

Event.occurrences is grabbing my occurrences over a time period for
me, which I'm displaying in list form. For each occurrence, I want to
create an edit link back to the event that is the parent of the
occurrence, but how do I do that? In other words, how do I access the
ID of the event from within the occurrence? Is this built into the
Occurrence object as a property I have to define?

If not, I've had no luck assigning non-standard properties like:

@occurrence.event = self

or

@occurrence.event_id = @id

Any help would be appreciated.

dwayne

unread,
Oct 24, 2009, 12:03:19 AM10/24/09
to RiCal
OK, I see, there's no Occurrence object, there is just a series of
"child" Event objects without recurrence rules.

The fix I came up with is to embed the ID of my parent object into the
occurrences while I enumerate them:

@occurrences = @events.collect do |e|
e.ical.occurrences(:overlapping => [DateTime.new(@year,
@month).beginning_of_month, DateTime.new(@year,
@month).end_of_month]).each { |o| o.add_related_to e.id.to_s }
end.flatten!

So, for a given month, I grab all events, enumerate the occurrences
and put the parent event ID into the related_to property for each.

I used related_to because I doubt I'll use it for anything else, but
is there a defined place where this information is supposed to go?
Reply all
Reply to author
Forward
0 new messages