code: def _to_primary_key(self, value):
          
          if value is None:
              return None
          if isinstance(value, self.base_class):
              if not value._is_loaded:
                  raise exceptions.DatabaseError('Record must be loaded.')
              return value._primary_key
  
          return self.base_class._to_primary_key(value)
docs: Return primary key; if value is StoredObject, verify
          that it is loaded.