-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
self.reload prone to error #122
Comments
I have this same issue, any info on how to work around this would be much appreciated! |
@alvinsj @jpbullalayao I'm looking into this while investigating #131. Since my issue will likely need I'm trying to fix my issue and I'd like to not introduce other issues with reload. |
I have also been bit by this. I think the problem is that require 'active_record' # 4.2.5
require 'acts_as_list' # 0.7.2
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
create_table :lists
create_table :elements do |table|
table.integer :list_id
table.integer :position
end
end
class List < ActiveRecord::Base
has_many :elements
end
class Element < ActiveRecord::Base
belongs_to :list
acts_as_list scope: :list
end
list = List.new
x = list.elements.build
list.elements.each &:destroy
# ActiveRecord::RecordNotFound: Couldn't find Element without an ID I can fix this issue by overriding def reload_position
reload unless new_record?
end |
This should fix brendon#122.
Seems I'm hit by this bug too. Any news about the fix? |
I'll look into this. What's the scenario in which one is destroying records not yet persisted in the database? |
Not exactly. I try to destroy a record that has a It fails here: acts_as_list-0.7.3/lib/acts_as_list/active_record/acts/list.rb:481 |
Oh wait, maybe it is our fault. We overwrite |
Haha, sounds like fun. Definitely sounds like an out-of-order destroy problem. I've had something similar with |
Yeah this was fun. Observer, circle dependent destroys and before_validation callbacks. But now it works and it was not acts_as_list fault :) I'm glad I never used |
That's good to hear @swelther :) Glad you got your problem sorted. |
this issue is referring to this line of code.
I noticed active_record model is more or less destroy-safe. Meaning the children/parents of a model(e.g. dependent: destroy) can destroy the referring model, yet if model.destroy got called again before commit, it won't fail.
however, this self.reload like below has failed the program and raising
RecordNotFound
error.please let me know if i missed some code, or if anyone has a workaround for this.
The text was updated successfully, but these errors were encountered: