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.
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
one.
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
different one.
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
that
:dependent => :destroy wouldn’t be allowed to destroy the associated
object.
I must be missing something.
I feel really stupid right now but obviously I’ve missed something. I
don’t
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
presumed
that the problem was some kind of reference somewhere that I did wrong
and
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
necessary.
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 :).
I’m having similar problems with :dependent => :destroy not destroying
or
deleting the dependent records. I’m having to just call
association.clear in
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
spend
trying to figure it out this time. You’re not alone on this though.
RSL
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.