Ruby on Rails Sunday, January 30, 2011

On Jan 30, 10:27 pm, "Ellicks M." <li...@ruby-forum.com> wrote:
>
> 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.

Are you under the assumption that

parent = Event.new

rolling_event_one.parent = parent
rolling_event_two.parent = parent
rolling_event_three.parent = parent

creates 3 copies of parents? It doesn't (unless you've written parent=
to store a copy of parent)

Fred
>
> 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 viahttp://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