bug fix for RefferenceField.to_mongo when dbref=False
This commit is contained in:
parent
c31488add9
commit
787fc1cd8b
@ -777,7 +777,7 @@ class ReferenceField(BaseField):
|
|||||||
def to_mongo(self, document):
|
def to_mongo(self, document):
|
||||||
if isinstance(document, DBRef):
|
if isinstance(document, DBRef):
|
||||||
if not self.dbref:
|
if not self.dbref:
|
||||||
return DBRef.id
|
return document.id
|
||||||
return document
|
return document
|
||||||
elif not self.dbref and isinstance(document, basestring):
|
elif not self.dbref and isinstance(document, basestring):
|
||||||
return document
|
return document
|
||||||
|
@ -1104,6 +1104,15 @@ class FieldTest(unittest.TestCase):
|
|||||||
|
|
||||||
p = Person.objects.get(name="Ross")
|
p = Person.objects.get(name="Ross")
|
||||||
self.assertEqual(p.parent, p1)
|
self.assertEqual(p.parent, p1)
|
||||||
|
|
||||||
|
def test_dbref_to_mongo(self):
|
||||||
|
class Person(Document):
|
||||||
|
name = StringField()
|
||||||
|
parent = ReferenceField('self', dbref=False)
|
||||||
|
|
||||||
|
p1 = Person._from_son({'name':"Yakxxx", 'parent': "50a234ea469ac1eda42d347d"})
|
||||||
|
mongoed = p1.to_mongo()
|
||||||
|
self.assertIsInstance(mongoed['parent'], ObjectId)
|
||||||
|
|
||||||
def test_objectid_reference_fields(self):
|
def test_objectid_reference_fields(self):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user