Permanently delete associations in callback
Closed this issue · 2 comments
The dependent records which are deleted by the callbacks are not destroyed permanently when i call destroy(:force).
This is my scenario. I am on Rails 2.3.5
class User < ActiveRecord::Base
has deleted_at column
has_many :photos, :dependent => :destroy
end
class Book < ActiveRecord::Base
has deleted_at column
belongs_to :user
end
user = User.find(1)
user.destroy(:force) #=> deletes user records but not photos table records permanently. It only sets
# deleted_at of the photos table.
It would be great to know if there is anything we can do by manipulating the callback reflections for the association and let the photos records also deleted permanently ?
Interestingly, I have just the opposite problem. My scenario runs on Rails 3.2.3 and permanent_records 2.3.0
class User < ActiveRecord::Base
#does NOT have deleted_at column
has_many :photos, :dependent => :destroy
end
class Photo < ActiveRecord::Base
#has deleted_at column
belongs_to :user
end
Then
> user = User.find(1)
> user.destroy #=> first updates deleted_at for associated photos, but then actually hard-deletes them as well!
For me, this was surprising behavior -- definitely worth noting!
@udayakiran @davetchen There does seem to be a difference in the old release of permanent_records regarding callbacks. Rails 3.x has dependent records destroyed (even permanently) while 2.x doesn't.
Only Rails 3+ is supported now but you could fairly easily fork the project and hack the source to allow your 2.x Rails app to work as you like.