Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor updates for proxy

  • Loading branch information...
commit 85f4f18b2e381907d3f4dad50dbb9d45457927bc 1 parent d7820bf
Jeff Jenkins authored
Showing with 5 additions and 6 deletions.
  1. +5 −6 mongoalchemy/fields/ref.py
View
11 mongoalchemy/fields/ref.py
@@ -24,8 +24,8 @@
from bson import DBRef
class RefBase(Field):
- def rel(self):
- return Proxy(self)
+ def rel(self, allow_none=False):
+ return Proxy(self, allow_none=allow_none)
class SRefField(RefBase):
''' A Simple RefField (SRefField) looks like an ObjectIdField in the
@@ -115,8 +115,6 @@ def unwrap(self, value, fields=None, session=None):
value.type = self.type
return value
- def rel(self):
- return Proxy(self)
def dereference(self, session, ref, allow_none=False):
from mongoalchemy.document import collection_registry
# TODO: namespace support
@@ -147,7 +145,8 @@ def validate_unwrap(self, value, session=None):
validate_wrap = validate_unwrap
class Proxy(object):
- def __init__(self, field):
+ def __init__(self, field, allow_none=False):
+ self.allow_none = allow_none
self.field = field
def __get__(self, instance, owner):
if instance is None:
@@ -156,7 +155,7 @@ def __get__(self, instance, owner):
ref = getattr(instance, self.field._name)
if ref is None:
return None
- return self.field.dereference(session, ref)
+ return self.field.dereference(session, ref, allow_none=self.allow_none)
def __set__(self, instance, value):
assert instance is not None
setattr(instance, self.field._name, self.field._to_ref(value))
Please sign in to comment.
Something went wrong with that request. Please try again.