views:

26

answers:

1

Poking around in the rails code, I ran across with_scope.

From what I can tell, it takes the scope type and conditions, merges them into existing conditions for that scope type, yields to the block, then gets rid of the additional scope.

So my first thought is in a multithreaded environment (like jruby on rails), what happens if while thread 1 is executing the block, thread 2 decides to do a Model.find :all? It seems to me like a race condition waiting to happen.

Am I missing something?

A: 

So the trick in here is that if you trace deep enough, the scopes are getting set through Thread.current[method], which will execute method but only in the scope of the current thread. I didn't even know that was possible for ruby... guess you learn something new every day

Matt Briggs