Thanks for the advice. The "self" thing makes sense.

Interestingly, any attempts to set self.activeTrip caused a recursive
spiral of death ("Stack level too deep")
But I discovered that setting the active_trip_id property was the only
solution that worked safely, (also using "after :create" instead of
"before :save")

  after :create do
    # Set activeTrip if not already set:
    if self.activeTrip.nil?
      self.active_trip_id = self.id
      self.save
    end
  end


On Nov 3, 10:36 am, "Dan Kubb (dkubb)" <dan.k...@gmail.com> wrote:
> George,
>
> > The following code does not seem to work. After creating a new object
> > the active_trip_id field is blank in the database. Any ideas what I'm
> > doing wrong?
>
> ...
>
> >     # Default activeTrip to itself if none specified:
> >     before :save do
> >       activeTrip ||= self
> >     end
>
> The first thing I'd try is prefix the assignment with self, eg:
> self.activeTrip ||= self
>
> Without that you're assigning to a local variable, not the object
> accessor/mutator.
>
> --
>
> Dan
> (dkubb)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to datamapper@googlegroups.com
To unsubscribe from this group, send email to 
datamapper+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to