Better implementation of ‚Prevent saving of detached models (see #6506)‘