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]