sliver
sliver

Reputation: 1660

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

Upvotes: 3

Views: 94

Answers (1)

Devin M
Devin M

Reputation: 9752

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

Upvotes: 2

Related Questions