6
6
from mongoengine .base import get_document
7
7
8
8
from . import advanced_types
9
- from .utils import import_single_dispatch , get_field_description , get_query_fields
9
+ from .utils import import_single_dispatch , get_field_description , get_query_fields , camel_to_snake
10
10
11
11
singledispatch = import_single_dispatch ()
12
12
@@ -172,13 +172,13 @@ def convert_field_to_dynamic(field, registry=None):
172
172
173
173
def reference_resolver (root , * args , ** kwargs ):
174
174
document = getattr (root , field .name or field .db_name )
175
- only_fields = get_query_fields (args [0 ]).keys ()
176
- return field .document_type .objects ().only (* only_fields ).get (pk = document .id )
175
+ only_fields = [ camel_to_snake ( i ) for i in get_query_fields (args [0 ]).keys ()]
176
+ return field .document_type .objects ().no_dereference (). only (* only_fields ).get (pk = document .id )
177
177
178
178
def cached_reference_resolver (root , * args , ** kwargs ):
179
- document = getattr ( root , field . name or field . db_name )
180
- only_fields = get_query_fields ( args [ 0 ]). keys ()
181
- return field .document_type . objects (). only ( * only_fields ). get ( pk = document )
179
+ only_fields = [ camel_to_snake ( i ) for i in get_query_fields ( args [ 0 ]). keys ()]
180
+ return field . document_type . objects (). no_dereference (). only ( * only_fields ). get (
181
+ pk = getattr ( root , field .name or field . db_name ) )
182
182
183
183
def dynamic_type ():
184
184
_type = registry .get_type_for_model (model )
@@ -201,10 +201,9 @@ def convert_lazy_field_to_dynamic(field, registry=None):
201
201
model = field .document_type
202
202
203
203
def lazy_resolver (root , * args , ** kwargs ):
204
- if getattr (root , field .name or field .db_name ):
205
- only_fields = get_query_fields (args [0 ]).keys ()
206
- document = getattr (root , field .name or field .db_name )
207
- return document .document_type .objects ().only (* only_fields ).get (pk = document .pk )
204
+ document = getattr (root , field .name or field .db_name )
205
+ only_fields = [camel_to_snake (i ) for i in get_query_fields (args [0 ]).keys ()]
206
+ return document .document_type .objects ().no_dereference ().only (* only_fields ).get (pk = document .pk )
208
207
209
208
def dynamic_type ():
210
209
_type = registry .get_type_for_model (model )
0 commit comments