whoops, don't dereference all references as the first type encountered
This commit is contained in:
parent
a1d43fecd9
commit
49a66ba81a
@ -112,10 +112,11 @@ class DeReference(object):
|
|||||||
for ref in references:
|
for ref in references:
|
||||||
if '_cls' in ref:
|
if '_cls' in ref:
|
||||||
doc = get_document(ref["_cls"])._from_son(ref)
|
doc = get_document(ref["_cls"])._from_son(ref)
|
||||||
|
elif doc_type is None:
|
||||||
|
doc = get_document(
|
||||||
|
''.join(x.capitalize()
|
||||||
|
for x in col.split('_')))._from_son(ref)
|
||||||
else:
|
else:
|
||||||
if doc_type is None:
|
|
||||||
doc_type = get_document(
|
|
||||||
''.join(x.capitalize() for x in col.split('_')))
|
|
||||||
doc = doc_type._from_son(ref)
|
doc = doc_type._from_son(ref)
|
||||||
object_map[doc.id] = doc
|
object_map[doc.id] = doc
|
||||||
return object_map
|
return object_map
|
||||||
|
@ -815,17 +815,29 @@ class FieldTest(unittest.TestCase):
|
|||||||
class Foo(Document):
|
class Foo(Document):
|
||||||
meta = {'allow_inheritance': False}
|
meta = {'allow_inheritance': False}
|
||||||
bar = ReferenceField('Bar')
|
bar = ReferenceField('Bar')
|
||||||
|
baz = ReferenceField('Baz')
|
||||||
|
|
||||||
class Bar(Document):
|
class Bar(Document):
|
||||||
meta = {'allow_inheritance': False}
|
meta = {'allow_inheritance': False}
|
||||||
msg = StringField(required=True, default='Blammo!')
|
msg = StringField(required=True, default='Blammo!')
|
||||||
|
|
||||||
|
class Baz(Document):
|
||||||
|
meta = {'allow_inheritance': False}
|
||||||
|
msg = StringField(required=True, default='Kaboom!')
|
||||||
|
|
||||||
Foo.drop_collection()
|
Foo.drop_collection()
|
||||||
Bar.drop_collection()
|
Bar.drop_collection()
|
||||||
|
Baz.drop_collection()
|
||||||
|
|
||||||
bar = Bar()
|
bar = Bar()
|
||||||
bar.save()
|
bar.save()
|
||||||
|
baz = Baz()
|
||||||
|
baz.save()
|
||||||
foo = Foo()
|
foo = Foo()
|
||||||
foo.bar = bar
|
foo.bar = bar
|
||||||
|
foo.baz = baz
|
||||||
foo.save()
|
foo.save()
|
||||||
foo.reload()
|
foo.reload()
|
||||||
|
|
||||||
|
self.assertEquals(type(foo.bar), Bar)
|
||||||
|
self.assertEquals(type(foo.baz), Baz)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user