0

Is it possible to use sql during the construction of an ActiveRecord object?

For example,

@user = User.new
@user.name = params[:name]
@user.via_sql.id = `select count(1) from users`
@user.save

This is just a silly example, but I need to deal with a concurrency problem.

I'd like to be able to do this so I can still use ActiveRecord callbacks.

Glenn
  • 59
  • 6
  • Please state the actual problem you're having, maybe there is a "Rails" way to solve it. That being said, there is a method called `find_by_sql`. – Eyeslandic Jun 06 '14 at 18:58
  • 1
    My actual problem is dealing with incrementing a value, while dealing with a concurrency issue: http://stackoverflow.com/questions/24086570/rails-incrementing-integers-from-db-with-concurrency/24086648#24086648 Thanks. – Glenn Jun 06 '14 at 22:22

0 Answers0