Created
January 26, 2010 12:03
-
-
Save SKoschnicke/286781 to your computer and use it in GitHub Desktop.
Concurrency problems with Rails' ActiveRecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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