I have a Production model, which represents a farmer’s crop. After
create (via after_save) I call a method that creates one or more
Supply models, which represent a week of anticipated product harvest.
After each of those are created, a class method gets called that tries
to match each new Supply with outstanding orders for the same time
period. If a match is made, a transaction (an Exchange model acting as
the join record) is created and it adjusts the quantities in both the
Supply and Order models.
Well, it ain’t working. I mean, it almost does, but after_save filter
seems to be calling methods during the transaction, not after the
commit. The quantity updates on the Supply and Order models are
getting blown away. It seems I was mislead by the name of
“after_save”.
before_save doesn’t work because the id for the Production hasn’t been
assigned and the relationships can’t be set then.
First, are my observations about after_save and the transaction
correct? Second, is there another callback filter I should be using
instead, one that happens after the transaction? Or is my design
suspect? Recommendations welcome.
Thanks!