Catch 22 with after_save. Please help

I have a pretty strange problem. Here is basically what I have to
demonstrate my problem:

class Event < ActiveRecord::Base
def after_create
AnotherClass.find_event(id)
end
end

class AnotherClass < ActiveRecord::Base
def self.find_event(event_id)
e = Event.find event_id
end
end

Here is the catch 22 and it’s quite annoying. Basically ActiveRecord
puts to whole save action into a transaction. If an exception is
raised in the after_create method it rolls back the transaction, as
if the save never happened. The problem is that during the
transaction the save is never committed to the database. So
AnotherClass.find_event raises the exception “Can’t find event with
id=34” or whatever id it had, because the transaction hasn’t been
committed. That exception then rolls back the transaction, creating a
catch 22.

So basically what I’m asking if there an after_after_create method?
ha ha. Basically a method that gets called after the transaction is
committed.

Also, in case you were wondering I did set up an EventObserver and
get the same exact problem.

Lastly, I can not pass the object because AnotherClass is in a
background process and passing methods between processes is not
permitted. I’m using backgroundrb for this.

Any help is greatly appreciated.

Thank You,
Ben J.
E: [email protected]

On Jul 18, 2006, at 6:40 PM, Ben J. wrote:

def self.find_event(event_id)
with id=34" or whatever id it had, because the transaction hasn’t
Lastly, I can not pass the object because AnotherClass is in a
background process and passing methods between processes is not
permitted. I’m using backgroundrb for this.

Any help is greatly appreciated.

Thank You,
Ben J.
E: [email protected]

Hey Ben-

Actually there is a way to pass full instantiated active record

objects to the drb server. What you need to do is in your model class
definition you need to add the following line to each model you want
to send over the wire to the drb server:

include DRbUndumped

And then you can pass the objects to the drb server and back.

-Ezra