Actually you can (in some way). Since .all
returns an array, not an active write relation, what exactly could you delete? I would not say that Record.all.destroy is logical at all - are you deleting an array object?
One thing you can do is map the resulting array, and since map
accepts proc ( &
), you can execute this proc for every object in your array.
Record.all.map(&:destroy)
Note that this will cause callbacks for all of your objects, which may be slower than you planned. If you want to avoid callbacks, you can map the corresponding destructive method instead of destroying it. (hint :: delete)
Alternatively, you can simply:
Record.destroy_all or Record.delete_all
as you stated in your question.
saneshark
source share