Question: I have very strange behaviour when I'm initialising new User.

I run code like `@user = User.where(:provider => @provider, :uid => @shop[:uid]).first_or_initialize`

setting all neded data and then saving `@user.save`

But then when I pass user id immediately after saving to Worker

`EmailWelcome.perform_async @user.id`

It passes `nil` as user id.. So my question has anybody seen such behaviour with \*\_initialize methods and what should I do? 

**EDIT:** Also need to mention, that it saves record in DB

Answer: 
Are you sure that the id is nil when it's being sent to the worker? Or that the worker process just can't find the user based on the id that's given to the job?

If you are using a worker process like resque or sidekiq, it won't have access to the user until the transaction completes. If that's the problem, you need to use `after_commit` or some other way to queue up the `EmailWelcome` job *after* the transaction completes.
I was just looking for an answer to the same problem. I have multiple databases and it was working on dev but not staging.

The id column on the staging column was missing the auto-increment sequence (in postgres).

Something else for you to check.

HTH