MS SQL Server (ODBC mode)
I have the following class:
class Document < ActiveRecord::Base
has_many :images, :dependent => :delete_all
has_many :stylesheets, :dependent => :delete_all
In one of my controllers, I do:
and no deletes are performed against my database, which is clearly
If, however, I use script/console to do the same exact destroy call with
the same id, the cascaded delete works just fine.
I can hand code the cascaded delete, of course, but would like for
:dependent => :delete_all to work as advertised.
I know that it’s a long shot, but has anyone seen anything like this?
If I replace the call to the AR Base class method destroy with a call to
the instance method destroy on that particular object, then the deletes
appear to work correctly.
That’s strange - any ideas?
This seems like a reasonable idea. However, the fact that this object
is frozen when you do a “destroy” on it keeps me from building a new
So I have current_job.document, and I call current_job.document.destroy
and then I can’t call current_job.build_document (I get a “can’t modify
frozen hash” error).
Frankly, I don’t understand why this happens - I’m not trying to modify
the original document object, I’m trying to replace it with a whole
In general, it appears that once you have an association, you can’t
destroy it and then expect to be able to replace it with another object.
What’s up with that?
I must be missing something because it doesn’t seem reasonable to me
:dependent => :destroy wouldn’t be allowed to destroy the associated
I must be missing something.
The destroy is allowed to happen but then you can’t replace the object
I feel really stupid right now but obviously I’ve missed something. I
see that you [or I] are trying to replace any objects but destroy them.
Sorry for being so thick about this but I’m honestly confused. I
that the problem was some kind of reference somewhere that I did wrong
because it couldn’t clear, the associated object never deletes.
You and I have the same problem vis a vis deleting and I am also calling
.clear explicitly on the child objects. I too do not know why this is
My additional issue is that once I do the destroy on the child object,
I cannot then create a new child object because the reference is frozen.
So I’m complaining about that :).
Gotcha. I thought I was missing someething.
Someone suggested that I reload the current_job model variable using
and then perhaps I can do
Anyone know if this is correct?
I’m having similar problems with :dependent => :destroy not destroying
deleting the dependent records. I’m having to just call
the after_destroy. Oddly, using association.clear in the before_destroy
isn’t working for me either. It feels like there’s something going on
preventing the association#destroy to fail but I don’t have time to
trying to figure it out this time. You’re not alone on this though.