# File lib/couchrest/model/design.rb, line 36
      def sync!(db = nil)
        db ||= database

        # Load up the last copy. We never blindly overwrite the remote copy
        # as it may contain views that are not used or known about by
        # our model.
        doc = load_from_database(db)

        if !doc || doc['couchrest-hash'] != checksum
          # We need to save something
          if doc
            # Different! Update.
            doc.merge!(to_hash)
          else
            # No previous doc, use a *copy* of our version.
            # Using a copy prevents reverse updates.
            doc = to_hash.dup
          end
          db.save_doc(doc)
        end

        self
      end