My Rails app offers opportunities to try out models on a 'what-if'
basis, where dependent associations can be modified to obtain
alternative results for the parent. Is there a way to delete/destroy
the member of a collection so that I can play around with the
accordingly modified parent in memory, without actually committing the
destruction of the collection member to the data store? Based on my
read of the docs, there is no 'delete' counterpart to
'collection.build' for association members.
My Rails app offers opportunities to try out models on a 'what-if'
basis, where dependent associations can be modified to obtain
alternative results for the parent. Is there a way to delete/destroy
the member of a collection so that I can play around with the
accordingly modified parent in memory, without actually committing the
destruction of the collection member to the data store? Based on my
read of the docs, there is no 'delete' counterpart to
'collection.build' for association members.
If it were my app, I think I'd do this differently: start a transaction
for the "what if" stuff, then either roll it back or commit it when
done.
I'm not sure why you are worried about touching the data store.
collection.build doesn't save the new object so there is nothing in
the db that could be deleted.
If all you want to do is revert collection.build just remove that
element of the association array (as pepe pointed out).