Open niels opened 8 years ago
My workaround:
module Disposable
class Twin
class Collection
def direct_destroy(twin)
delete_at(index(twin))
twin.model.destroy
end
end
end
end
Oh, I didn't even know there's a different behavior implicated.
Suppose I have a
Twin A
that contains a collection ofTwins B
.Twin B
is backed by a database table. Collection membership is indicated by atwin_a_id
column on theTwin B
database table. That column has a not-null constraint as noTwin B
should ever exist that isn't associated with aTwin A
.Given the above, I can't remove a
Twin B
from the collection.Twin::Collection
always wants to callTwin::Collection#delete
, even when actually using#destroy
.#delete
will try to persist to the database by nullifyingtwin_a_id
, thus violating the not-null constraint, thus raising an exception.Perhaps
#destroy
should just destroy the associatedTwin
(as one might naively expect the name to imply)? Users who actually want to delete, then destroy, would then have to do so manually by calling both methods. Of course this would be a backwards-incompatible change..