Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is an active record really inserted into the database

We have a server setup where a rails server is writting into the same database as an java enterprise server. We have an api for the enterprise server implemented on the rails server that will create a user. It looks like this:

    user = User.new
    user.name = "Test"
    user.save()

The problem we are facing now is that when the user create request returns the user id to the enterprise server it sometimes is not found by the enterprise server in the database.

When does ActiveRecord insert a new entity into the database? Is there a way to ensure that when save returns that the database insert statement was performed?

The rails version is 2.3.10

like image 353
sliver Avatar asked Apr 21 '26 10:04

sliver


1 Answers

You would want to use ActiveRecord callbacks for this. They let you perform an action after the save takes place.

like image 162
Devin M Avatar answered Apr 23 '26 22:04

Devin M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!