> Why do event occurrences not store their parent event rather than the
> object_id? Whatever you do ObjectSpace is really best avoided. I'm
> still not sure why this is better/more expressive than calculating
> them on the fly - you're clearly able to calculate the occurrences
> pragmatically, so I don't see why calculating them ahead of time would
> be less flexible/slower than calculating them on demand (provided you
> cache things so that you don't calculate things repeatedly)
>
> Fred
>
> Fred
Hi Fred,
I thought grabbing an instance of an object was probably a bad idea.
If the event occurrences (RollingEvents as they're called) actually
store their parent event then they would not be any better than storing
multiple copies of the event itself.
The aim here is to have an array that can be selected from and iterated
over without having to store the same data x number of times. A user
may have 200 Events, repeating weekly. They want to get a balance 20
years down the line. That would require 200*52*20 (or lots of) Events,
yet essentially only 200 different sets of data.
Example:
Event(id = 20135, title = "Rent", amount = "200.0", repeat_type_id = 2,
repeat_interval = 1, event_type = "E", exception_count = 0, calendar_id
= 13722, calendar_date = "2010-04-16")
repeat_type_id of 2 means this event repeats every repeat_interval weeks
(or 1x7 days). Now, this Event example is not all of an Events data,
but you can see how this is unwanted:
Event(id = 20135, title = "Rent", amount = "200.0", repeat_type_id = 2,
repeat_interval = 1, event_type = "E", exception_count = 0, calendar_id
= 13722, calendar_date = "2010-04-23")
Event(id = 20135, title = "Rent", amount = "200.0", repeat_type_id = 2,
repeat_interval = 1, event_type = "E", exception_count = 0, calendar_id
= 13722, calendar_date = "2010-04-30")
Event(id = 20135, title = "Rent", amount = "200.0", repeat_type_id = 2,
repeat_interval = 1, event_type = "E", exception_count = 0, calendar_id
= 13722, calendar_date = "2010-05-06")
Event(id = 20135, title = "Rent", amount = "200.0", repeat_type_id = 2,
repeat_interval = 1, event_type = "E", exception_count = 0, calendar_id
= 13722, calendar_date = "2010-05-13")
Event(id = 20135, title = "Rent", amount = "200.0", repeat_type_id = 2,
repeat_interval = 1, event_type = "E", exception_count = 0, calendar_id
= 13722, calendar_date = "2010-05-20")
...and so on
I was hoping to have something like this:
all_events = [RollingEvent(parent_event_object_id = 0x3c55d12, date =
"2010-04-16"),
RollingEvent(parent_event_object_id = 0x3c55d12, date = "2010-04-23"),
RollingEvent(parent_event_object_id = 0x3c55d12, date = "2010-04-30"),
RollingEvent(parent_event_object_id = 0x3c55d12, date = "2010-04-06"),
RollingEvent(parent_event_object_id = 0x3c55d12, date = "2010-04-13")]
and use:
er.all_events.select{|e| e.calendar_id == 2}.each{ etc etc etc}
Cheers,
Ellicks
P.S. Thank you for your help :)
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment