Skip to content

Instantly share code, notes, and snippets.

@SKoschnicke
Created January 26, 2010 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SKoschnicke/286781 to your computer and use it in GitHub Desktop.
Save SKoschnicke/286781 to your computer and use it in GitHub Desktop.
Concurrency problems with Rails' ActiveRecord
class A < ActiveRecord::Base
# has attribute "value"
end
class B < ActiveRecord::Base
has_many :as
def calc_b
result = Array.new
as.each do |a|
result << a.value
end
result
end
end
class SomeController
def index
@as = A.all
# assume here happends a database write
@b = B.first
# now @b.calc_b is inconsistent to the values of the objects in @as
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment