You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I have a Twin A that contains a collection of Twins B. Twin B is backed by a database table. Collection membership is indicated by a twin_a_id column on the Twin B database table. That column has a not-null constraint as no Twin B should ever exist that isn't associated with a Twin A.
Given the above, I can't remove a Twin B from the collection. Twin::Collection always wants to call Twin::Collection#delete, even when actually using #destroy. #delete will try to persist to the database by nullifying twin_a_id, thus violating the not-null constraint, thus raising an exception.
Perhaps #destroy should just destroy the associated Twin (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..
The text was updated successfully, but these errors were encountered:
niels
changed the title
Twin::Collection doesn't provide a "direct delete"
Twin::Collection can't remove members backed by a DB table with not-null constraint
Apr 22, 2016
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..The text was updated successfully, but these errors were encountered: