def validate_unwrap(self, value, session=None):
''' Validates that the DBRef is valid as well as can be done without
retrieving it.
'''
if not isinstance(value, DBRef):
self._fail_validation_type(value, DBRef)
if self.type:
expected = self.type.type.get_collection_name()
got = value.collection
if expected != got:
self._fail_validation(value, '''Wrong collection for reference: '''
'''got "%s" instead of "%s" ''' % (got, expected))
if self.db_required and not value.database:
self._fail_validation(value, 'db_required=True, but not database specified')
if self.db and value.database and self.db != value.database:
self._fail_validation(value, '''Wrong database for reference: '''
''' got "%s" instead of "%s" ''' % (value.database, self.db) )
评论列表
文章目录